Re: Strategy for unit testing GTK+ applications in C

2015-05-18 Thread Murray Cumming
On Sun, 2015-05-17 at 07:04 -0500, Daniel Espinosa wrote:
> I think your idea of keep processes in a library and create unit tests
> to it and then link to your GUI app is the better approach.
> 
> GDA[1] have a processes non-GUI library, a GUI library of widgets and
> a GUI app. You should check it.

Or don't even create a library if you don't need one. Just link your
tests to only the sources that the tests need to use. This works out
neatly when you can manage to keep some of your source code separate
from any UI or use of GTK+. To create unit tests the various parts of
your source code need to be loosely coupled anyway.

-- 
Murray Cumming
murr...@murrayc.com
www.murrayc.com


___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Strategy for unit testing GTK+ applications in C

2015-05-17 Thread richard boaz
you also might want to have a look at google test. at first glance, it
seems to satisfy your needs:

http://en.wikipedia.org/wiki/Google_Test

On Sat, May 16, 2015 at 4:45 AM, John Tall  wrote:

> Hello.
>
> I'm about to start working on a new GTK+ application that will be
> written in C. I want to use unit tests, probably the GTest APIs from
> GLib.
>
> I've used the GTest APIs before when building a library. What I did
> then was that I put all the source code for the library in one
> directory, all unit tests in another directory. Using Automake I built
> each unit test as a standalone program that linked to the library, and
> could just run each unit test to test the library.
>
> This time however I'm building an application, so it will already have
> its own main routine. I can't link my unit tests to the application
> because that would give me two main routines, the main entry point of
> the application and the main entry point of the unit test. So my
> question is how to construct the application so that I can test it
> with unit tests?
>
> My first thought was to just build the entire application as a library
> and link the unit tests with it, then all I would need for the actual
> application would be a separate program that just creates an instance
> of my GtkApplication subclass and runs it. It would be small enough
> that it doesn't need any unit tests, and I could even link it
> statically when installing the program.
>
> This sounds to me like the perfect solution, but I haven't found other
> applications that follows the same approach. I would therefore like to
> ask if this is a good idea or if there are better ways to do this?
> Especially if there are good examples from existing applications that
> I could look at that would be very useful.
>
> John
> ___
> gtk-list mailing list
> gtk-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-list
>
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Strategy for unit testing GTK+ applications in C

2015-05-17 Thread Florian Pelz
On 05/16/2015 11:45 AM, John Tall wrote:
> This time however I'm building an application, so it will already have
> its own main routine. I can't link my unit tests to the application
> because that would give me two main routines, the main entry point of
> the application and the main entry point of the unit test. So my
> question is how to construct the application so that I can test it
> with unit tests?
> 

It is be possible to link an application in a way that does not call
main but a different function on start-up. I've never used them, but I
believe linker scripts can do that. It probably is less portable though.

> My first thought was to just build the entire application as a library
> and link the unit tests with it, then all I would need for the actual
> application would be a separate program that just creates an instance
> of my GtkApplication subclass and runs it. It would be small enough
> that it doesn't need any unit tests, and I could even link it
> statically when installing the program.
> 

This is what I would do, but I don't know what is common -- other than
doing no unit testing at all, of course.



signature.asc
Description: OpenPGP digital signature
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Strategy for unit testing GTK+ applications in C

2015-05-17 Thread Daniel Espinosa
I think your idea of keep processes in a library and create unit tests to
it and then link to your GUI app is the better approach.

GDA[1] have a processes non-GUI library, a GUI library of widgets and a GUI
app. You should check it.

[1] git.gnome.org/browse/libgda
 El may 16, 2015 4:45 AM, "John Tall"  escribió:

> Hello.
>
> I'm about to start working on a new GTK+ application that will be
> written in C. I want to use unit tests, probably the GTest APIs from
> GLib.
>
> I've used the GTest APIs before when building a library. What I did
> then was that I put all the source code for the library in one
> directory, all unit tests in another directory. Using Automake I built
> each unit test as a standalone program that linked to the library, and
> could just run each unit test to test the library.
>
> This time however I'm building an application, so it will already have
> its own main routine. I can't link my unit tests to the application
> because that would give me two main routines, the main entry point of
> the application and the main entry point of the unit test. So my
> question is how to construct the application so that I can test it
> with unit tests?
>
> My first thought was to just build the entire application as a library
> and link the unit tests with it, then all I would need for the actual
> application would be a separate program that just creates an instance
> of my GtkApplication subclass and runs it. It would be small enough
> that it doesn't need any unit tests, and I could even link it
> statically when installing the program.
>
> This sounds to me like the perfect solution, but I haven't found other
> applications that follows the same approach. I would therefore like to
> ask if this is a good idea or if there are better ways to do this?
> Especially if there are good examples from existing applications that
> I could look at that would be very useful.
>
> John
> ___
> gtk-list mailing list
> gtk-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-list
>
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Strategy for unit testing GTK+ applications in C

2015-05-16 Thread John Tall
Hello.

I'm about to start working on a new GTK+ application that will be
written in C. I want to use unit tests, probably the GTest APIs from
GLib.

I've used the GTest APIs before when building a library. What I did
then was that I put all the source code for the library in one
directory, all unit tests in another directory. Using Automake I built
each unit test as a standalone program that linked to the library, and
could just run each unit test to test the library.

This time however I'm building an application, so it will already have
its own main routine. I can't link my unit tests to the application
because that would give me two main routines, the main entry point of
the application and the main entry point of the unit test. So my
question is how to construct the application so that I can test it
with unit tests?

My first thought was to just build the entire application as a library
and link the unit tests with it, then all I would need for the actual
application would be a separate program that just creates an instance
of my GtkApplication subclass and runs it. It would be small enough
that it doesn't need any unit tests, and I could even link it
statically when installing the program.

This sounds to me like the perfect solution, but I haven't found other
applications that follows the same approach. I would therefore like to
ask if this is a good idea or if there are better ways to do this?
Especially if there are good examples from existing applications that
I could look at that would be very useful.

John
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list