Commit Graph

345 Commits

Author SHA1 Message Date
Matthew Duggan
d058083888 ULTIMA8: Add some unit tests for base U8 classes 2020-02-29 16:29:33 -08:00
Bastien Bouclet
bb27669026 COMMON: Refill the stream buffer after making a large read
After reading directly from the parent stream, the buffer needs to be
filled with the end of the read data so seeking back in the stream into
the buffered area and reading returns data consistent with the parent
stream.

Fixes bug #11342 (PSP port only).
2020-02-07 18:33:56 +01:00
Jaromir Wysoglad
1346dcc3ef TESTBED: Move encoding conversion tests to testbed
This way it is possible to test the backend conversions too.
2019-08-24 18:12:45 +03:00
Jaromir Wysoglad
5fcd14fbea TEST: Remove tests for ascii transliteration
This can be handled differently by each conversion method.
The "Šáleček" could be transliterated as "Salecek" or as
"S'alecek" or maybe even differently.
2019-08-24 18:12:45 +03:00
Jaromir Wysoglad
3513972e92 TEST: Add tests for Common::Encoding 2019-08-24 18:12:45 +03:00
Bastien Bouclet
d474e3f94f ALL: Sync with ScummVM - rev. ea3f8f2e33 2019-06-29 19:08:44 +02:00
Bastien Bouclet
148655f5c2 COMMON: Use a prefix table to speed up the Huffman decoder
Symbols for codes shorter than the prefix table index width are stored
in the table. All the entries in the table with an index starting with
the code are set to the symbol value. That way, when decoding it is
possible to get the number of bits corresponding to the table width from
the bitstream and directly find the symbol value. Longer code still need
to be searched for in the codes list.
2019-04-14 20:24:26 +02:00
Bastien Bouclet
c087c5320c COMMON: Rework the BitStream class to improve its performance
* Fixed peekBits not to seek the underlying stream. Seeking can be slow
  when the stream is a file.
* Changed multi-bit  operations to work on multiple bits at once rather
  than iterating over single-bit operations.

This is an almost direct port of a patch for xoreos provided by DrMcCoy.
2019-04-14 20:22:50 +02:00
Bastien Bouclet
0f57aea2df COMMON: Use a prefix table to speed up the Huffman decoder
Symbols for codes shorter than the prefix table index width are stored
in the table. All the entries in the table with an index starting with
the code are set to the symbol value. That way, when decoding it is
possible to get the number of bits corresponding to the table width from
the bitstream and directly find the symbol value. Longer code still need
to be searched for in the codes list.
2019-04-13 16:24:25 +03:00
Bastien Bouclet
ae9eeb731f COMMON: Rework the BitStream class to improve its performance
* Fixed peekBits not to seek the underlying stream. Seeking can be slow
  when the stream is a file.
* Changed multi-bit  operations to work on multiple bits at once rather
  than iterating over single-bit operations.

This is an almost direct port of a patch for xoreos provided by DrMcCoy.
2019-04-13 16:24:25 +03:00
Thierry Crozat
563520f5c8 TESTS: Reduce error for double precision math test
If we want to properly test the computation is in double precision,
we should be using a much smaller error than the one used for the
single precision tests.
2019-04-12 01:37:59 +01:00
David Fioramonti
322af3e49a TESTS: Use relative difference for math tests
Also add double template variants and use already defined delta
assert macro.
2019-04-11 17:20:00 -07:00
David Fioramonti
cf0e9bfc1b TESTS: further reduce precision for math tests
Since the math is doing subtraction on numbers around 360 and single
precision has about ~7 decimal digits of accuracy we can only
compare numbers to 360.0001 to be safe i'll use 1e-3.
2019-04-11 16:50:07 -07:00
David Fioramonti
9b993aed00 TESTS: reduce precision for math tests
I can't reproduce any precision issues on my machine so this
is only a guess.
2019-04-11 15:59:45 -07:00
David Fioramonti
edb93c4606 TESTS: Use Less than or equal to for math tests
This should fix debian build.

Its seems the precision that debian is using is rounding the
error delta to zero so that the actual error is not less than
this.
2019-04-11 04:35:30 -07:00
David Fioramonti
07f806697d TESTS: Use M_PI for Common math tests
Instead of defining a new variable constant pi we use M_PI.
2019-04-06 20:34:08 -07:00
Jaromir Wysoglad
56397ae457 COMMON: add tests for Common::String
I added tests for firstChar, setChar, insertChar
2019-04-06 15:02:58 +03:00
Jaromir Wysoglad
bf5999044b COMMON: add test for Common::isPunct 2019-04-06 15:02:58 +03:00
Jaromir Wysoglad
b070845a31 COMMON: add 2 tests for common/math.h 2019-04-06 15:02:58 +03:00
sluicebox
85333d8050 COMMON: Allow '\#' to match '#' in matchString
matchString patterns couldn't be used to find files with the # character
as it was only treated as a digit wildcard. SCI expected that to work as
it looks for files that start with the # character.
2019-03-03 22:44:29 +02:00
Bastien Bouclet
3ec01653c3 ALL: Merge from ScummVM rev 3a933138ce 2017-12-06 21:41:03 +01:00
Colin Snover
b89b9095d6 TESTS: Remove zero-length string and associated -Wformat massage
This was being patched out downstream in Debian. A solution that
works for everybody is to just not use a zero-length string when
testing formatting with no conversion specifications.
2017-11-20 21:50:06 -06:00
Colin Snover
9f465b4062 TESTS: Remove unnecessary heap allocation 2017-11-18 16:52:15 -06:00
Colin Snover
076667dc00 COMMON: Add limited support for custom deleters to ScopedPtr
Custom deleters of ScopedPtr are not currently fully conforming to
C++11's support for custom deleters in std::unique_ptr for the
sake of simplicity of implementation. Unlike in the standard
library, plain functions and lvalue references are not supported,
nor may custom deleters be passed to the constructor at runtime.
This can be improved in the future, if necessary, by doing what
standard library implementations usually do and creating a Pair
class that uses the Empty Base Optimization idiom to avoid extra
storage overhead of the deleter instance when it is not needed, as
in typical standard library implementations, plus some additional
type traits to support the necessary metaprogramming for the
different type overloads.
2017-11-18 22:35:12 +01:00
Colin Snover
dda0f77bcf COMMON: Add basic fixed-width word wrap to Common::String 2017-11-10 09:57:41 -06:00
Colin Snover
f037d4df16 COMMON: Allow construction of Arrays of non-copyable members
Although the previous count-constructor would never make a copy of
a member at runtime, Array<T>::reserve *may* copy-construct, so
the compiler would forbid creation of arrays of NonCopyable objects
even when the array was created only once and then never resized
(and thus never actually tried to perform a copy-construction).
2017-10-06 22:10:50 -05:00
Colin Snover
4938d5cc76 COMMON: Add standard data method to Common::Array
This matches the C++11 std::vector method of the same name, and
replaces usage of taking the address of the first element of an
array by &array[0] or &array.front() or &*array.begin(). The data
method is better than these usages because it can be used even
when the array is empty.
2017-09-30 11:17:53 +02:00
Colin Snover
c867a1834f COMMON: Add standard count & count+copy array constructors
These are additions to match C++11 std::vector common init
patterns, to make Common::Array cover more common use cases where
C-style arrays are currently used (and should not be).
2017-09-30 11:17:53 +02:00
Bastien Bouclet
84e62b6c8d ALL: Sync with ScummVM - rev. 87ebc7140c 2017-09-02 15:04:07 +02:00
Willem Jan Palenstijn
0c8f95603f COMMON: Add BitStream classes for memory buffers 2017-08-24 19:46:59 +02:00
Colin Snover
58c83dcd14 COMMON: Make SpanOwner copy assignment make a copy of the owned Span
To move data from one SpanOwner to another, use `moveFrom`.
Thanks @waltervn for pointing out the problem.
2017-06-08 10:45:55 -05:00
Colin Snover
993d83fe4b COMMON: Reduce maximum Span size to 4GiB
Until C++11 (which introduces the z and t length modifiers), there
is no consistent way to print size_t and ptrdiff_t types using
printf formatting across 32-bit, LLP64, and LP64 architectures
without using a cumbersome macro to select the appropriate length
modifier for the target architecture. Since ScummVM engines
currently need to support 32-bit targets, there is no reason at
the moment to support any larger memory sizes in Span anyway.

Span error output is also updated in this commit to reflect that
index values are unsigned.
2017-03-30 14:22:56 -05:00
Colin Snover
f1d9955540 COMMON: Fix calling Span::getStringAt with non-zero index 2017-02-08 12:05:14 -06:00
Eugene Sandulenko
3bd85ef313 TESTS: Fix tests building 2017-01-23 21:58:38 +01:00
Eugene Sandulenko
37bb3abce4 TESTS: Revert changes to module Makefile
The recent changes were made in attempt to fix the test building
for NDS target, but since we're not building tests there, these
changes are reverted for the sake of cleaner code.
2017-01-23 21:34:47 +01:00
Eugene Sandulenko
4212734b1e TESTS: Fix missing QUIET_CXX option in Makefile 2017-01-23 21:11:03 +01:00
Eugene Sandulenko
595770368c TESTS: Attempt to fix Makefile for NDS build 2017-01-23 21:07:08 +01:00
Eugene Sandulenko
320ed53f31 TESTS: Fix linking target in Makefile 2017-01-23 20:52:52 +01:00
Colin Snover
9ff41967a0 BUILD: Fix PSP build of test runner 2017-01-15 18:32:07 -06:00
Colin Snover
5d22cc438f BUILD: Fix N64 build of test runner 2017-01-15 13:49:33 -06:00
Eugene Sandulenko
c46697be48 TESTS: Build Wintermute test only for static plugin 2017-01-15 18:30:13 +01:00
Colin Snover
871c9d26b2 BUILD: Fix compilation of test runner on Dreamcast
LIBS needs to go after LDFLAGS for the Dreamcast linker to run
correctly.
2017-01-15 11:17:52 -06:00
Colin Snover
4510c3ec27 TESTS: Attempt to fix buildbot builds for backends with extra flags 2017-01-14 16:45:32 -06:00
Bastien Bouclet
ce343f7168 TESTS: Fix building Common::Span test on big endian systems 2017-01-14 10:36:04 +01:00
Colin Snover
3cfc396ecd COMMON: Simplify Span code
Implicitly generated constructors can be used instead of explicit
constructors, which reduces the amount of necessary boilerplate.

Long lists of identical typedefs to the superclass are now defined
using a macro.

data() const now returns a pointer to data that matches the
value_type of the data, instead of forcing the data to be const.
This better matches the intent of the Span class, which provides
a view into data, rather than being a container that holds data.
2017-01-08 14:08:16 -06:00
Colin Snover
9c60bcf069 COMMON: Add more lcov-guided Span tests 2017-01-08 13:21:10 -06:00
Colin Snover
2558b20cdd COMMON: Improve test coverage for Span and fix bugs from testing 2017-01-08 13:20:23 -06:00
Colin Snover
640f6039ca COMMON: Add Span to common library
Span is roughly modelled on the GSL span<T> type, and is intended
to replace direct access to raw pointers -- especially pointers
that are passed to functions along with a separate size
parameter. It provides low-cost bounds-checked reads and writes,
as well as convenience functions for reading common values
(integers of varying endianness, strings, etc.). While similar to
MemoryReadStream in purpose, Span is superior in cases where
memory is writable, where memory is accessed randomly rather than
sequentially, or where any invalid access should be treated as an
unrecoverable error. It should also be more efficient than a
MemoryReadStream because it is implemented using CRTP, so there is
no runtime overhead from dynamic dispatch.

NamedSpan is an extension of Span which provides enhanced
debugging information when out-of-bounds memory accesses occur.
It allows programmers to name the memory span at construction time,
and it also tracks the offsets of subspans so that the absolute
byte offset of the original memory can be provided in the error
message if an out-of-bounds access occurs.

SpanOwner is similar to ScopedPtr but has awareness of the design
of Span objects, so allows the memory pointed to by the Span object
inside the SpanOwner to be freed when the SpanOwner is freed
without requiring holding a separate pointer to the start of
memory. It also provides some copy semantics, so unlike a ScopedPtr,
SpanOwners can be held by objects in movable containers like
Common::Array -- but note that because there are no move semantics
in C++98, this means that a new, complete memory copy of the
pointed-to data will be created, rather than just a new Span
pointing to the same block of memory, when a container holding a
SpanOwner expands.
2017-01-08 13:20:23 -06:00
Willem Jan Palenstijn
c919c9996c TESTS: Fix warnings 2017-01-05 22:07:24 +01:00
Colin Snover
9d3893459f COMMON: Add strnlen for safer C string length reads
This API is intended for use in cases where C strings come
from untrusted sources like game files, where malformed data
missing the null terminator would cause strlen to read out of
bounds.
2017-01-05 22:07:24 +01:00
Colin Snover
6687d9c1ab TEST: Only build Wintermute tests when that engine is enabled 2016-12-27 12:30:24 -06:00
Eugene Sandulenko
8477c4beb2 Merge pull request #874 from tobiatesan/fix_getfilename_cr5
WINTERMUTE: Fix PathUtils and add workaround for mixed separators
2016-12-26 16:15:38 +01:00
Tobia Tesan
72376681af WINTERMUTE: Try to "correctly" handle dir paths
I put scare quotes around "correctly" because I can't swear this is the
intended behaviour of the original interpreter.

I don't think accessing filenames that end with / in the .DCPs is even
defined behaviour, so this is a best guess.
2016-12-26 12:05:41 +01:00
Tobia Tesan
9339490236 WINTERMUTE: only access -1th char of string if length > 0 in getFileName
Fixes #6594
2016-12-26 12:02:56 +01:00
Tobia Tesan
e3fdd8d5fe WINTERMUTE: Add tests for engines/wintermute/path_utils.h 2016-12-26 10:41:48 +01:00
Pawel Kolodziejski
19bcd1f3bc ALL: Sync with ScummVM 2016-11-12 12:59:06 +01:00
Pawel Kolodziejski
9ba9c69b3f ALL: Sync with ScummVM - rev. 823c2f899b 2016-11-12 08:49:29 +01:00
Eugene Sandulenko
355c4fa646 JANITORIAL: Remove more trailing spaces 2016-10-09 15:02:02 +02:00
Eugene Sandulenko
78e240c23b TESTS: Fix warning 2016-09-05 08:24:37 +02:00
Bastien Bouclet
8d34d5190d Revert "BUILD: Fix test compilation with event recorder enabled"
This reverts commit 1f8667c5d9.
2016-07-28 18:23:50 +02:00
Eugene Sandulenko
e0d445bb74 TESTS: Fix SortedArray test 2016-06-04 13:49:55 +02:00
Eugene Sandulenko
5a8eb1c9d6 TESTS: Implement SortedArray test 2016-05-23 16:36:34 +02:00
Eugene Sandulenko
1f8667c5d9 BUILD: Fix test compilation with event recorder enabled 2016-05-23 16:36:26 +02:00
Borja Lorente Escobar
a19b50ddf2 COMMON: Add replace functions to Common and String.
COMMON: Add replacement to common/algorithm.h

COMMON: Intermediate commit to show doubts.

 COMMON: Basic String::replace() methods implemented.

COMMON: Fix typo in the algorithm.h documentation.

COMMON: Fix documentation of String::replace()

COMMON: Fix formatting issues in method signatures.

COMMON: Add assert and reformat loops in str and algorithm.

COMMON: Fix typo in comment.

COMMON: Fix style in string test cases.

COMMON: Add Doxygen documentation to algorithm and String.

COMMON: Add Doxygen documentation to algorithm and String.

COMMON: Add Doxygen documentation to algorithm.

COMMON: Fix style in algorithm comments.

COMMON: Add Doxygen comments to String.

COMMON: Add Doxygen comments to algorithm test function.

COMMON: Add String support for substring replace.

COMMON: Fix string replace to comply with STL

COMMON: Fix documentation on string replace

COMMON: Fix style in string replace

COMMON: Fix unwanted reference problem in String::replace().

COMMON: Fix indentation in comments for replace

COMMON: Fix indentation in replace

COMMON: Fix comments in String::replace to match implementation.

COMMON: Remove assert to allow for not-null-terminated character arrays

COMMON: Add new test for String::replace

COMMON: Fix broken comments on String::replace

COMMON: Fix sharing bug on ensureCapacity

COMMON: Remove superfluous call to makeUnique()
2016-05-16 22:01:21 +02:00
Colin Snover
4ba0ff8deb COMMON: Add convenience method to Common::Rational for 1:1 ratios
For SCI engine games, ratios may not be normalised and so to avoid
extra scaling, there needs to be a way to simply check whether a
ratio is 1:1.
2016-02-18 13:18:02 -06:00
Colin Snover
7d54f0aaaf COMMON: Add methods for inserting and erasing with iterators
This provides improved feature parity to Common::List and is used
in SCI32 engine.
2016-02-18 13:18:01 -06:00
Pawel Kolodziejski
6c960b1d33 ALL: Sync with ScummVM 2016-01-30 21:18:08 +01:00
Johannes Schickel
06641f29a7 COMMON: Allow '#' to only match digits in matchString. 2016-01-26 16:35:30 +01:00
Pawel Kolodziejski
2fadf2e466 ALL: Synced with ScummVM 2015-12-22 00:24:01 +01:00
Bertrand Augereau
5ad9cd1a1a COMMON: More sort unit tests 2015-11-10 20:30:51 +01:00
Pawel Kolodziejski
c5ccf4d423 ALL: synced with ScummVM 2015-01-25 19:31:35 +01:00
clone2727
79c902338b TEST: Use "/usr/bin/env python" as the shebang line in cxxtestgen.py 2015-01-18 14:41:16 -05:00
Pawel Kolodziejski
a4fc7ea3b2 ALL: synced with scummvm 2015-01-12 23:50:20 +01:00
Johannes Schickel
ba228f2bea TEST: Fix another typo in uint64 endian tests. 2015-01-04 21:22:43 +01:00
Johannes Schickel
daa8fca001 TEST: Fix uint64 endian related test code.
This does not fix the actual implementation issues which are present right
now!
2015-01-04 21:09:32 +01:00
Johannes Schickel
f1e58efe90 TEST: Fix C++11 compat warnings. 2015-01-04 21:09:32 +01:00
Eugene Sandulenko
9abd92a711 Merge pull request #508 from RichieSams/add_endian_and_stream_support_for_int64
COMMON: Add support for endian-safe reading/writing of int64
2015-01-04 19:50:33 +01:00
Pawel Kolodziejski
86876c6bbc ALL: synced with ScummVM 2014-12-21 16:09:34 +01:00
Adrian Astley
93167fabb5 TEST: Create test cases for reading uint64 from a stream 2014-12-21 04:12:43 -06:00
Bastien Bouclet
200b05246c AUDIO: Wrap around in the Timestamp constructor
The "making of" video in the Xbox version of Myst III is
unusually long. VideoDecoder::FixedRateVideoTrack::getFrameTime
would trigger an overflow.
2014-12-20 19:38:18 +01:00
Adrian Astley
a4685796ce TEST: Add unit tests for uint64 reading 2014-12-19 11:53:32 -06:00
Joseph Jezak
99fa91053c MATH: Rename XYZ Rotation Functions to Euler to better describe the function. 2014-09-11 13:38:28 -04:00
Pawel Kolodziejski
1a07a23294 ALL: synced with ScummVM 2014-08-18 05:21:52 +02:00
Johannes Schickel
bb70ea04e9 TEST: Remove odd test in rendermode tests.
This specific test checked whether the pointer for two static strings have a
different address. Since the specific strings checked had the same "value"
string pooling optimizations will result in them to have the same address and
thus make this test fail. Furthermore, the test seemed completely pointless,
I simply dropped it now.
2014-08-07 15:04:13 +02:00
Joseph Jezak
c1b5adf348 MATH: Add new quaternion capability. 2014-07-01 16:18:08 -04:00
Joseph Jezak
76d36f676b MATH: Add a selectable Euler Order to Rotation3D. 2014-06-23 09:04:25 -04:00
Pawel Kolodziejski
8759900b6a ALL: synced with ScummVM 2014-04-05 18:18:42 +02:00
Max Horn
4d02f67bd1 ALL: Resolve multiple clang warnings 2014-03-30 14:38:02 +02:00
Pawel Kolodziejski
790db038c0 ALL: sync with scummvm 2013-10-13 11:30:34 +02:00
Max Horn
bd0db73a64 BUILD: fix 'make test' compile error 2013-08-05 11:44:27 +02:00
Pawel Kolodziejski
f52da5c053 ALL: synced with scummvm 2013-07-16 22:11:39 +02:00
Tobia Tesan
d2c85e19eb TEST: Whitespaces in test/common/ 2013-07-10 13:22:57 +02:00
Tobia Tesan
e9406fad24 TEST: removed fixed hashes in test/common/hash-str.h
The hash function does not necessarily have to conform to one specific algorithm as long as equals/differs is respected.
2013-07-10 13:22:01 +02:00
Tobia Tesan
6245a68632 TEST: Thorough testing for common/hash-str.h
We test the various equal_to and hash functions therein.
2013-07-10 13:21:24 +02:00
Tobia Tesan
2e4933dcd5 TEST: reorganize test/common/util.h
Split a few test cases in two.
The resulting file is now better organized.
2013-07-10 13:17:59 +02:00
Tobia Tesan
377789db77 TEST: tests for common/rendermode.h
tests for parseRenderMode, renderMode2GUIO and getRenderModeCode.
2013-07-10 13:17:52 +02:00
Tobia Tesan
4a18eab8a5 TEST: test cases for common/util.cpp 2013-07-10 13:17:47 +02:00
Tobia Tesan
4f7d92acb4 TEST: tests for common/huffman.h
A few tests for the Huffman decoder.

The encoding is the example from Wikipedia.
This could be improved by someone more knowledgeable by
generating one at runtime or using multiple encodings
which would each contain one edge case.
2013-07-10 13:17:41 +02:00
Pawel Kolodziejski
068ff94d20 ALL: synced with ScummVM 2013-07-07 15:29:33 +02:00
richiesams
e1ff60da7a COMMON: Add erase method to String class 2013-06-20 15:40:25 -05:00