Commit Graph

115 Commits

Author SHA1 Message Date
Iain Lane
51d566ba6e test_paths: Reindent to avoid tripping -Wmisleading-indentation
This fixes:

glib/tests/testglib.c: In function ‘test_paths’:
glib/tests/testglib.c:955:3: error: this ‘if’ clause does not guard... [-Werror=misleading-indentation]
   if (g_test_verbose ())
   ^~
glib/tests/testglib.c:958:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
     {
     ^

https://bugzilla.gnome.org/show_bug.cgi?id=796385
2018-05-30 10:07:35 +01:00
Georges Basile Stavracas Neto
b9b642de06 fileutils: Add g_canonicalize_filename
Getting the canonical filename is a relatively common
operation when dealing with symbolic links.

This commit exposes GLocalFile's implementation of a
filename canonicalizer function, with a few additions
to make it more useful for consumers of it.

Instead of always assuming g_get_current_dir(), the
exposed function allows passing it as an additional
parameter.

This will be used to fix the GTimeZone code to retrieve
the local timezone from a zoneinfo symlink.

(Tweaked by Philip Withnall <withnall@endlessm.com> to drop g_autofree
usage and add some additional tests.)

https://bugzilla.gnome.org/show_bug.cgi?id=111848
2018-04-30 21:54:31 +01:00
Philip Withnall
9b4c50f63d all: Remove trailing newlines from g_message()/g_warning()/g_error()s
All those logging functions already add a newline to any message they
print, so there’s no need to add a trailing newline in the message
passed to them.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-04-27 16:46:19 +01:00
Philip Withnall
5cddde1fb2 Consistently save errno immediately after the operation setting it
Prevent the situation where errno is set by function A, then function B
is called (which is typically _(), but could be anything else) and it
overwrites errno, then errno is checked by the caller.

errno is a horrific API, and we need to be careful to save its value as
soon as a function call (which might set it) returns. i.e. Follow the
pattern:
  int errsv, ret;
  ret = some_call_which_might_set_errno ();
  errsv = errno;

  if (ret < 0)
    puts (strerror (errsv));

This patch implements that pattern throughout GLib. There might be a few
places in the test code which still use errno directly. They should be
ported as necessary. It doesn’t modify all the call sites like this:
  if (some_call_which_might_set_errno () && errno == ESOMETHING)
since the refactoring involved is probably more harmful than beneficial
there. It does, however, refactor other call sites regardless of whether
they were originally buggy.

https://bugzilla.gnome.org/show_bug.cgi?id=785577
2017-08-03 10:21:13 +01:00
Sébastien Wilmet
f6c44ec3e4 tests/: LGPLv2+ -> LGPLv2.1+
gen-casefold-txt.pl and gen-casemap-txt.pl are licensed under GPLv2+, so
they are not touched by this commit.

A lot of *.c files in tests/ don't have a license header.

https://bugzilla.gnome.org/show_bug.cgi?id=776504
2017-05-29 19:53:35 +02:00
Simon McVittie
45dae4b506 tests: replace most g_print() with g_printerr()
I searched all files that mention g_test_run, and replaced most
g_print() calls. This avoids interfering with TAP. Exceptions:

* gio/tests/network-monitor: a manual mode that is run by
  "./network-monitor --watch" is unaffected
* glib/gtester.c: not a test
* glib/gtestutils.c: not a test
* glib/tests/logging.c: specifically exercising g_print()
* glib/tests/markup-parse.c: a manual mode that is run by
  "./markup-parse --cdata-as-text" is unaffected
* glib/tests/testing.c: specifically exercising capture of stdout
  in subprocesses
* glib/tests/utils.c: captures a subprocess's stdout
* glib/tests/testglib.c: exercises an assertion failure in g_print()

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=725981
Reviewed-by: Colin Walters <walters@verbum.org>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-05-11 20:24:56 +01:00
Simon McVittie
0a9d91ab7b testglib: my_hash_callback_remove_test: actually fail the test
The test is to remove all the odd values with my_hash_callback_remove(),
then iterate over all values and verify that they are even. However,
failing this check would just print "bad!" instead of failing the test.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=725981
Reviewed-by: Colin Walters <walters@verbum.org>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-05-11 20:24:50 +01:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01:00
Matthias Clasen
27e352985b Remove broken attempt at parsing date-only
g_time_val_from_iso8601 was attempting to parse strings
having only a date, but failed to actually set the timeval
despite returning TRUE. Since the docs state that the function
only parses strings containing a date and a time, just return
FALSE in this case.

Also remove an incomplete testcase for this behaviour that was
just checking the boolean return value, but not timeval.
2014-01-01 17:59:21 -05:00
Chun-wei Fan
ccba409d34 tests/: Avoid closing invalid fd's
...and only include unistd.h when we are on *NIX.

Newer Visual C++ runtimes (8.0/2005 and later) will cause the program to
crash with an internal abort() call when they detect instances of close()
being called on an invalid fd, such as when the fd is -1, and these should
be purged anyways.

https://bugzilla.gnome.org/show_bug.cgi?id=711047
2013-11-11 22:36:32 +08:00
Dan Winship
e3d1869ee3 tests: port from g_test_trap_subprocess() to g_test_trap_fork()
https://bugzilla.gnome.org/show_bug.cgi?id=679683
2013-05-13 12:10:52 -04:00
Matthias Clasen
0178402c6d Revert "tests: port from g_test_trap_subprocess() to g_test_trap_fork()"
This reverts commit ea06ec8063.
2012-12-19 15:20:37 -05:00
Dan Winship
ea06ec8063 tests: port from g_test_trap_subprocess() to g_test_trap_fork()
(or, in a few cases, to g_test_expect_message())

https://bugzilla.gnome.org/show_bug.cgi?id=679683
2012-12-19 14:35:10 -05:00
Simon McVittie
29f2ced8eb various GLib tests: plug memory leaks
These don't really matter, since it's test code, but they do obscure
real leaks in the library.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=666115
Acked-by: Matthias Clasen <mclasen@redhat.com>
2011-12-14 12:40:16 +00:00
Simon McVittie
a0f5e89aed testglib: test_file_functions: don't close fd if it's -1
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=666115
Reviewed-by: Matthias Clasen <mclasen@redhat.com>
2011-12-14 12:40:02 +00:00
Will Thompson
5e2a2ef288 g_parse_debug_string: invert flags given besides "all"
Any flags specified as well as "all" are subtracted from the result,
allowing the user to specify FOO_DEBUG="all,bar,baz" to mean "give me
debugging information for everything except bar and baz".

https://bugzilla.gnome.org/show_bug.cgi?id=642452
2011-10-24 20:35:30 -04:00
Will Thompson
73ffa9034f Test g_parse_debug_string ("all")
https://bugzilla.gnome.org/show_bug.cgi?id=642452
2011-10-24 20:26:22 -04:00
Ryan Lortie
ce9681b87e Drop a few more G_CONST_RETURN 2011-06-13 09:27:28 -04:00
Matthias Clasen
abf4a0200f Test runtime dir getter 2011-06-06 00:30:30 -04:00
Matthias Clasen
316be2748f Adapt testglib.c to GRelation deprecation
Patch by Chun-wei Fan, bug https://bugzilla.gnome.org/show_bug.cgi?id=637858
2010-12-28 00:12:19 -05:00
Tor Lillqvist
46390c9d10 Don't call close() on -1
Of course, a proper implementation of close() will just ignore an
invalid parameter silently, and set errno. But apparently the "debug"
version of the Microsoft C library generates some noise in this
case. So avoid that. Thanks to John Emmas for reporting.
2010-10-07 12:06:48 +03:00
Jens Georg
db7ddcc195 Improve parsing of date-only iso8601 strings 2010-08-26 18:18:52 +03:00
Juan A. Suarez Romero
992e07c8b2 Fix warnings
Do explicit casts to avoid warnings.
2010-06-09 10:32:12 +02:00
Tor Lillqvist
241c7f476d Don't use deprecated g_win32 API 2010-02-04 14:53:20 +02:00
Dan Winship
8212aadac7 g_time_val_from_iso8601: handle timezoneless dates
per ISO 8601:2004 4.2.5.2

Based on a patch from Andy Shevchenko
http://bugzilla.gnome.org/show_bug.cgi?id=589491
2009-09-01 09:40:03 -04:00
Peter Kjellerstedt
efc2cdbfc9 Fix parsing of timezones
Make g_time_val_from_iso8601 handle timezones with minutes correctly;
also accept comma as a fraction separator.  (#578369)
2009-04-08 10:26:11 -04:00
Matthias Clasen
88c7129340 Bug 547337 – G_DISABLE_DEPRECATED breaks tests build
2008-08-13  Matthias Clasen  <mclasen@redhat.com>

        Bug 547337 – G_DISABLE_DEPRECATED breaks tests build

        * tests/testglib.c: Protect deprecated API by ifdefs.
        Patch by Kalle Vahlman


svn path=/trunk/; revision=7353
2008-08-14 03:05:17 +00:00
Tor Lillqvist
b5b363019a Avoid warning on Win64 by using gintptr cast instead if long cast.
2008-08-04  Tor Lillqvist  <tml@novell.com>

	* tests/testglib.c: Avoid warning on Win64 by using gintptr cast
	instead if long cast.


svn path=/trunk/; revision=7304
2008-08-04 18:12:11 +00:00
Paolo Borelli
96f99d334d Bug 539770 - migrate gstrfunc unit tests to gtest
2008-06-24  Paolo Borelli  <pborelli@katamail.com>

	Bug 539770 - migrate gstrfunc unit tests to gtest

	* tests/strfunc-test.c:
	* tests/testglib.c:
	* tests/strtoll-test.c:
	* tests/strtod-test.c:
	* tests/string-test.c:
	* tests/Makefile.am:
	Removed old tests.

	* glib/tests/fileutils.c:
	* glib/tests/strfuncs.c:
	* glib/tests/Makefile.am:
	Added all the old tests migrated to the new unit test framework
	and add new unit tests for some of the functions.


svn path=/trunk/; revision=7097
2008-06-24 13:55:22 +00:00
Matthias Clasen
d780a41c37 set tv_usec to 0 rather than 1 when a fraction of a second is not
* glib/gtimer.c (g_time_val_from_iso8601): set tv_usec to 0 rather
        than 1 when a fraction of a second is not specified
        (g_time_val_from_iso8601): calculate a fraction of a second
        correctly even in case it does not happen to consist of exactly
        six digits; do not allow random data after the ISO 8601 string,
        only whitespace
        (make g_time_val_to_iso8601): support fractions of a second
        Patch by Peter Kjellerstedt

        * tests/testglib.c: Update to match


svn path=/trunk/; revision=7057
2008-06-19 04:14:25 +00:00
17:40:58 Tim Janik
d6682a1f2d fixed gstdio.h include.
2008-04-18 17:40:58  Tim Janik  <timj@imendio.com>

        * tests/testglib.c: fixed gstdio.h include.

        * tests/Makefile.am: properly list testglib.c SOURCES.



svn path=/trunk/; revision=6862
2008-04-18 15:40:38 +00:00
Matthias Clasen
fe751b255f Small test fixup
svn path=/trunk/; revision=6652
2008-03-10 15:13:29 +00:00
Matthias Clasen
11d7305d5a Don't test user directories for being non-null. (#517084, Yevgen Muntyan)
2008-02-23  Matthias Clasen  <mclasen@redhat.com>

        * tests/testglib.c: Don't test user directories for being
        non-null.  (#517084, Yevgen Muntyan)

svn path=/trunk/; revision=6562
2008-02-23 05:14:34 +00:00
Hans Breuer
1cda3c9e01 adapt to recent api changes variable declaration at the beginning of a
2007-12-09  Hans Breuer  <hans@breuer.org>

	* tests/gio-ls.c : adapt to recent api changes
	* tests/testglib.c : variable declaration at the beginning of a block
	
	(Lieven van der Heide, #503602)
	* win32-fixup.pl : process *.rc.in as well; substitute 
	LT_CURRENT_MINUS_AGE
	* glib/makefile.msc.in : alphabetic sorting of OBJECTS


svn path=/trunk/; revision=6184
2007-12-21 10:11:35 +00:00
Emmanuele Bassi
a979c0d5a2 Fix the date validation check. (#503029)
2007-12-19  Emmanuele Bassi  <ebassi@gnome.org>

	* glib/gtimer.c (g_time_val_from_iso8601): Fix the date validation
	check. (#503029)

	* tests/testglib.c (various_string_tests): Add an invalid date
	for testing the above fix.

svn path=/trunk/; revision=6160
2007-12-19 17:28:38 +00:00
16:06:11 Tim Janik
0efd85aeac split up tests and reworked code to use the new test framework.
2007-12-12 16:06:11  Tim Janik  <timj@imendio.com>

        * tests/testglib.c: split up tests and reworked code to use
        the new test framework.

        * tests/Makefile.am: added testglib to TEST_PROGS.



svn path=/trunk/; revision=6103
2007-12-12 15:09:08 +00:00
Matthias Clasen
d154485bc7 Add support for a number of special directories, as defined by the
2007-06-04  Matthias Clasen  <mclasen@redhat.com>

        Add support for a number of special directories, as
        defined by the xdg-user-dirs specification.  (#432651,
        Bastien Nocera, Emmanuele Bassi, Michael Natterer)

        * glib/glib.symbols:
        * glib/gutils.[hc]: Add the GUserDirectory enum and
        g_get_user_special_dir(), with implementations based
        on the xdg-user-dirs spec and on native interfaces
        for Win32 and Carbon.

        * configure.in: Add Carbon checks.

        * tests/tetsglib.c: Test g_get_user_special_dir().


svn path=/trunk/; revision=5528
2007-06-04 14:54:49 +00:00
Matthias Clasen
1f536d2f12 Fix an off-by-2 error in the leap year calculation. (#344905, Dan Winship)
2006-06-20  Matthias Clasen  <mclasen@redhat.com>

	* glib/gtimer.c (mktime_utc): Fix an off-by-2 error
	in the leap year calculation.  (#344905, Dan Winship)

	* tests/testglib.c (main): Change the test data for
	the g_time_val_from_iso8601 tests to expose an off-by-2
	error in the leap year calculation.
2006-06-20 16:37:43 +00:00
Emmanuele Bassi
6db9ec4070 Check for timegm.
2006-03-23  Emmanuele Bassi  <ebassi@cvs.gnome.org>

	* configure.in: Check for timegm.

	* glib/gtimer.h:
	* glib/gtimer.c:
	* glib/glib.symbols:
	* docs/reference/glib/glib-sections.txt: Added g_time_val_to_iso8601
	and g_time_val_from_iso8601, to convert a GTimeVal to and from an
	ISO 8601 encoded date.

	* tests/testglib.c: Added test cases for g_time_val_to_iso8601()
	and g_time_val_from_iso8601() functions.
2006-03-23 02:54:29 +00:00
Matthias Clasen
9e58246669 Don't read past the end of the string. (#334471, Morten Welinder)
2006-03-14  Matthias Clasen  <mclasen@redhat.com>

	* glib/gutils.c (g_parse_debug_string): Don't read past the
	end of the string.  (#334471, Morten Welinder)
2006-03-14 17:56:27 +00:00
Tor Lillqvist
b8c119f901 glib/gfileutils.c glib/gfileutils.h glib/glib.symbols Rename g_makepath()
2005-06-22  Tor Lillqvist  <tml@novell.com>

	* glib/gfileutils.c
	* glib/gfileutils.h
	* glib/glib.symbols
	* tests/testglib.c: Rename g_makepath() to g_mkdir_with_parents().
2005-06-22 18:55:33 +00:00
Tor Lillqvist
1833a93ddd New function. Creates a directory including intermediate parent
2005-06-22  Tor Lillqvist  <tml@novell.com>

	* glib/gfileutils.c (g_makepath): New function. Creates a
	directory including intermediate parent directories as
	needed. (#60509)

	* glib/gfileutils.h: Declare it.

	* glib/glib.symbols: Add it.

	* tests/testglib.c: Test it.
2005-06-22 09:43:37 +00:00
Tor Lillqvist
477989f555 New function. Returns the machine's name, or one of its names. Document
2005-06-22  Tor Lillqvist  <tml@novell.com>

	* glib/gutils.c (g_get_host_name): New function. Returns the
	machine's name, or one of its names. Document that it is
	best-effort only, and not guaranteed to be unique or anything.
	(g_get_any_init): Get the host name here. On Unix use
	gethostname(), on Windows use GetComputerName(). (#5200)

	* glib/gutils.h
	* glib/glib.symbols: Add here, too.

	* tests/testglib.c: Test it.
2005-06-22 08:54:28 +00:00
Tor Lillqvist
446c1f1aa8 Minor printout change, now identical as in glib-2-6 branch. 2005-03-20 20:08:23 +00:00
Tor Lillqvist
20378332ae Print more detailled output from the timer tests. Don't print home
2005-03-20  Tor Lillqvist  <tml@novell.com>

	* tests/testglib.c (main): Print more detailled output from the
	timer tests. Don't print home directory twice. Test
	g_win32_error_message().

	* tests/spawn-test.c (run_tests): On Win32, run netstat instead of
	ipconfig. On Windows XP collecting output from ipconfig doesn't
	seem to work for some reason.
2005-03-20 10:43:38 +00:00
Matthias Clasen
d209e108b1 Add a function to return a list of applicable locale names. (#95587,
2004-09-07  Matthias Clasen  <mclasen@redhat.com>

	* glib/gutils.h:
	* glib/gutils.c (g_get_language_names): Add a function to
	return a list of applicable locale names.  (#95587,
	Hidetoshi Tajima)
	(guess_category_value, compute_locale_variants):
	(explode_locale, unalias_lang, read_aliases): Helper
	functions for g_get_language_names()

	* tests/testglib.c (main): Show the results of
	g_get_language_names()
2004-09-07 18:37:10 +00:00
Tor Lillqvist
b359dbbf5e Test the new XDG basedir functions.
2004-08-26  Tor Lillqvist  <tml@iki.fi>

	* tests/testglib.c (main): Test the new XDG basedir functions.
2004-08-26 00:08:46 +00:00
Matthias Clasen
48deca6379 Trivial warning fix.
2004-04-22  Matthias Clasen  <mclasen@redhat.com>

	* tests/testglib.c (main): Trivial warning fix.
2004-04-22 20:58:37 +00:00
Matthias Clasen
05501852ec Add testcases for g_message() involving non-printable and unsafe
2004-04-22  Matthias Clasen  <mclasen@redhat.com>

	* tests/testglib.c (main): Add testcases for g_message() involving
	non-printable and unsafe characters.

	* glib/gmessages.c (escape_string): Don't assume that
	string->str remains unchanged over g_string_insert()
	calls.  (#139030, Christophe Saout)
2004-04-22 20:17:54 +00:00
Tim Janik
ee4e622d37 applied patch from #131937 with slight renames. provides
Fri Feb 20 03:02:05 2004  Tim Janik  <timj@gtk.org>

        * glib/ghash.[hc]: applied patch from #131937 with slight
        renames. provides g_hash_table_find().
2004-02-20 02:05:36 +00:00