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[] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be char?

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


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@DrMcCoy
Copy link
Member Author

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants