Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests #133

Merged
merged 81 commits into from Feb 25, 2017
Merged

Unit tests #133

merged 81 commits into from Feb 25, 2017

Conversation

@DrMcCoy
Copy link
Member

@DrMcCoy DrMcCoy commented Dec 21, 2016

This PR adds general unit tests (using Google Test) to xoreos.

It's not 100% coverage, far from it. There's currently 1034 indidual tests in 70 file (with ~ one class per file), covering most of Common, many of the Aurora classes and 3 files for image decoders.

Included in the changeset is also some CMake changes. @berenm, if you could double-check that what I did there makes sense, that would be great. Thanks.

I'm also enabling the unit tests in Travis CI and AppVeyor. The former seems to work, but for some reason, AppVeyor throws errors there. "Exception: Other", whatever that is supposed to mean. I don't suppose you might know what the issues is there, or how I can get more usual debug info, @berenm? Because that is just weird :/.

Going forward, more unit tests would be great. For example:

  • PE EXE file in common/ and PE file archive in aurora/.
  • Image decoders. Possible, but annoying to write.
  • Nintendo DS formats.
  • Aurora::ResourceManager? Would need functions to manipulate some structures more directly.
  • FFT/DCT/MDCT/RDFT? Would be fiddly.
  • Sound decoders, probably rather difficult to test. Video decoders doubly so.
  • Fonts and models would be neat, but also difficult. And currently, the loaders directly use OpenGL objects...
  • Engine-/game-level tests? World object structures? Script functions?

Likewise, new or changed functions in classes already covered by the tests should now be getting unit tests as well.

Comments, criticism, etc. welcome, of course. :)

#include "src/aurora/2dafile.h"
#include "src/aurora/gdafile.h"

static const byte k2DAASCII[] =

This comment has been minimized.

@clone2727

clone2727 Dec 21, 2016
Contributor

Should be char?

Yes, I know it ends up in a MemoryReadStream, but it seems odd to store text as byte here.

@DrMcCoy DrMcCoy force-pushed the test branch from afb01e9 to 1d8872a Dec 21, 2016

GTEST_TEST(BIFFile10, getNameHashAlgo) {
Common::MemoryReadStream *stream =
new Common::MemoryReadStream(kBIF10File, sizeof(kBIF10File));

This comment has been minimized.

@clone2727

clone2727 Dec 21, 2016
Contributor

Having to type the variable twice always bugs me, especially when it's easy to have a copy/paste error. Maybe it would be better to have something like this as a function in MemoryReadStream:

template <size_t N>
static MemoryReadStream *CreateFromArray(const byte (&array)[N]) {
    return new MemoryReadStream(array, N);
}
"Which yet survive, stamped on these lifeless things,\n"
"The hand that mocked them and the heart that fed:\n"
"And on the pedestal these words appear:\n"
"\'My name is Ozymandias, king of kings:\n"

This comment has been minimized.

@clone2727

clone2727 Dec 21, 2016
Contributor

You don't need to escape a single quote from within double quotes.

};

GTEST_TEST(ERFFile11NWN, getNameHashAlgo) {
const std::vector<byte> password(kERF11NWNPassword, kERF11NWNPassword + sizeof(kERF11NWNPassword));

This comment has been minimized.

@clone2727

clone2727 Dec 21, 2016
Contributor

Obviously can't modify std::vector, but a similar templated function as mentioned for MemoryReadStream might be nice to have.

@DrMcCoy DrMcCoy force-pushed the test branch 8 times, most recently from 69642fa to c76191b Dec 21, 2016
@DrMcCoy
Copy link
Member Author

@DrMcCoy DrMcCoy commented Dec 22, 2016

(AppVeyor:)
Okay, after a lot of fiddling (grrrr), it seems that many unit tests fail with error code -1073741515, which is 0xC0000135, which is STATUS_DLL_NOT_FOUND. Of course, it doesn't say which DLL...

The ones that do work are:

  • tests_common_test_scopedptr
  • tests_common_test_disposableptr
  • tests_common_test_ptrlist
  • tests_common_test_ptrvector
  • tests_common_test_ptrmap
  • tests_common_test_binsearch
  • tests_common_test_maths
  • tests_common_test_vector3
  • tests_common_test_matrix4x4
  • tests_common_test_boundingbox

All other unit tests fail. The ones that work are all small, contained classes/templates and might not even need any DLL at all...

@DrMcCoy DrMcCoy force-pushed the test branch 16 times, most recently from d4317a3 to c68a61c Dec 22, 2016
DrMcCoy added 27 commits Oct 6, 2016
@DrMcCoy DrMcCoy force-pushed the test branch from 81d1b0f to 1a14ac9 Feb 25, 2017
@DrMcCoy DrMcCoy merged commit 1a14ac9 into master Feb 25, 2017
4 checks passed
4 checks passed
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@DrMcCoy DrMcCoy deleted the test branch May 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants