Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Thu Apr 18, 2019 5:40 pm

All times are UTC




Post new topic  Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Automated tests
PostPosted: Thu Jan 17, 2019 5:49 pm 
Offline
Engineer
Engineer
User avatar

Joined: Fri Jan 11, 2019 3:03 am
Posts: 11
Location: New York, NY
I think OpenTTD would benefit from some unit tests. Have there been any efforts to introduce automated testing to the codebase? I'll try and put something together with googletest (https://github.com/google/googletest).


Last edited by njn on Thu Feb 21, 2019 1:56 am, edited 2 times in total.

Top
   
 Post subject: Re: Automated tests
PostPosted: Fri Jan 18, 2019 9:55 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Wed Nov 07, 2007 10:44 pm
Posts: 9260
Location: Sol d
njn wrote:
I think OpenTTD would benefit from some unit tests. Have there been any efforts to introduce automated testing to the codebase? I'll try and put something together with googletest (https://github.com/google/googletest).


It might. But it's not easy to actually create/ run any unit tests on OpenTTD. But of course: be our guest :)

_________________
Image
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML


Top
   
 Post subject: Re: Automated tests
PostPosted: Thu Feb 21, 2019 1:52 am 
Offline
Engineer
Engineer
User avatar

Joined: Fri Jan 11, 2019 3:03 am
Posts: 11
Location: New York, NY
Alright, well in case anyone is interested... I've got a branch going for this here: https://github.com/OpenTTD/OpenTTD/pull/7254

I tried adding some tests for the ReallyAdjustBrightness() function in the 32bpp sse blitter, but I ran into some trouble compiling this object file in a standalone way, because it uses the _screen and _palette externs. This is possibly solvable, though. Anyways, any function with concrete inputs and outputs is a good candidate for unit testing.


Last edited by njn on Fri Feb 22, 2019 1:27 pm, edited 1 time in total.

Top
   
 Post subject: Re: Automated tests
PostPosted: Thu Feb 21, 2019 2:26 pm 
Offline
Tycoon
Tycoon

Joined: Wed Jan 17, 2007 12:14 am
Posts: 7312
njn wrote:
because it uses the _screen and _palette externs.

that's what i mean when i say it's hard to introduce unit tests when the program is already done, and not designed with units in mind. you get all theese interdependency issues that makes it difficult to isolate sections to test

_________________
You might not exactly be interested in Ferion, but if you are, have fun :)


Top
   
 Post subject: Re: Automated tests
PostPosted: Thu Feb 21, 2019 3:32 pm 
Offline
Route Supervisor
Route Supervisor
User avatar

Joined: Wed Jan 08, 2003 11:09 pm
Posts: 440
Location: Denmark
njn wrote:
I tried adding some tests for the ReallyAdjustBrightness() function in the 32bpp sse blitter, but I ran into some trouble compiling this object file in a standalone way, because it uses the _screen and _palette externs. This is possibly solvable, though. Anyways, any function with concrete inputs and outputs is a good candidate for unit testing.

This is where you will have to introduce some mocking. The palette and screen definitions seem to be pretty straight forward and can probably be defined as static (non-const) data in the test program.


Top
   
 Post subject: Re: Automated tests
PostPosted: Thu Feb 21, 2019 4:14 pm 
Offline
Engineer
Engineer
User avatar

Joined: Fri Jan 11, 2019 3:03 am
Posts: 11
Location: New York, NY
Eddi wrote:
njn wrote:
because it uses the _screen and _palette externs.

that's what i mean when i say it's hard to introduce unit tests when the program is already done, and not designed with units in mind. you get all theese interdependency issues that makes it difficult to isolate sections to test


These problems are very solvable.. you can either:
* Make the code more loosely coupled
* Mock out the interfaces that you need to just get things basically working for testing purposes, as jfs points out above. That's probably the route I'll take here, and will give me a chance to try out https://github.com/google/googletest/tree/master/googlemock


Top
   
 Post subject: Re: Automated tests
PostPosted: Thu Feb 21, 2019 5:35 pm 
Offline
Tycoon
Tycoon

Joined: Wed Jan 17, 2007 12:14 am
Posts: 7312
njn wrote:
These problems are very solvable..

yes, but it's an awful lot of grunt work

_________________
You might not exactly be interested in Ferion, but if you are, have fun :)


Top
   
 Post subject: Re: Automated tests
PostPosted: Fri Feb 22, 2019 1:28 pm 
Offline
Engineer
Engineer
User avatar

Joined: Fri Jan 11, 2019 3:03 am
Posts: 11
Location: New York, NY
Eddi wrote:
njn wrote:
These problems are very solvable..

yes, but it's an awful lot of grunt work


True.. it can definitely be seen that way. idk why I find it kinda fun / interesting. Maybe it's a personal problem >_<

I guess I like finding overlooked cases that aren't behaving correctly. In fact I already found one: the GreatestCommonDivisor() function can return negative integers when one of its inputs is negative. These should always be positive. This probably doesn't have any effect on the code, since I think it's only using this function with positive integers. But still, GreatestCommonDivisor() gladly accepts negative integers as input, so it might as well be correct.


Last edited by njn on Fri Feb 22, 2019 3:01 pm, edited 1 time in total.

Top
   
 Post subject: Re: Automated tests
PostPosted: Fri Feb 22, 2019 1:40 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Wed Nov 07, 2007 10:44 pm
Posts: 9260
Location: Sol d
njn wrote:
Eddi wrote:
njn wrote:
These problems are very solvable..

yes, but it's an awful lot of grunt work


True.. it can definitely be seen that way. idk why I find it kinda fun / interesting. Maybe it's a personal problem >_<


In science we have a saying: one person's noise is another person's data. Similar applies to what people consider fun work. Fortunately :)

_________________
Image
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2019 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2019.
Hosted by Zernebok Hosting.