[Scummvm-git-logs] scummvm master -> d0580838887efc746fa3a385514e1f0a2906e509
dreammaster
paulfgilbert at gmail.com
Sun Mar 1 00:29:36 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
d058083888 ULTIMA8: Add some unit tests for base U8 classes
Commit: d0580838887efc746fa3a385514e1f0a2906e509
https://github.com/scummvm/scummvm/commit/d0580838887efc746fa3a385514e1f0a2906e509
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2020-02-29T16:29:33-08:00
Commit Message:
ULTIMA8: Add some unit tests for base U8 classes
Changed paths:
A test/engines/ultima/shared/core/str.h
A test/engines/ultima/ultima8/misc/box.h
A test/engines/ultima/ultima8/misc/id_man.h
A test/engines/ultima/ultima8/misc/memset_n.h
A test/engines/ultima/ultima8/misc/util.h
A test/engines/ultima/ultima8/usecode/bit_set.h
A test/engines/ultima/ultima8/usecode/uc_list.h
A test/engines/ultima/ultima8/usecode/uc_stack.h
engines/ultima/ultima8/usecode/uc_stack.h
test/module.mk
diff --git a/engines/ultima/ultima8/usecode/uc_stack.h b/engines/ultima/ultima8/usecode/uc_stack.h
index 173a60c2ca..d1a04b6a84 100644
--- a/engines/ultima/ultima8/usecode/uc_stack.h
+++ b/engines/ultima/ultima8/usecode/uc_stack.h
@@ -24,6 +24,7 @@
#define ULTIMA8_USECODE_UCSTACK_H
#include "common/scummsys.h"
+#include "ultima/shared/std/misc.h"
namespace Ultima {
namespace Ultima8 {
diff --git a/test/engines/ultima/shared/core/str.h b/test/engines/ultima/shared/core/str.h
new file mode 100644
index 0000000000..98a2185aa6
--- /dev/null
+++ b/test/engines/ultima/shared/core/str.h
@@ -0,0 +1,39 @@
+#include <cxxtest/TestSuite.h>
+#include "engines/ultima/shared/core/str.h"
+
+/**
+ * Test suite for the functions in engines/ultima/shared/core/str.h
+ */
+
+class UltimaStrSuite : public CxxTest::TestSuite {
+
+ public:
+ UltimaStrSuite () {
+ }
+
+ void test_index_of() {
+ Ultima::Shared::String s = " a ";
+ TS_ASSERT_EQUALS(s.indexOf(' '), 0);
+ TS_ASSERT_EQUALS(s.indexOf('a'), 2);
+ TS_ASSERT_EQUALS(s.indexOf('z'), -1);
+
+ s = " alksjdf ][";
+ TS_ASSERT_EQUALS(s.indexOf("3245j9083f45"), 5);
+ TS_ASSERT_EQUALS(s.indexOf("0123456789"), -1);
+ }
+
+ void test_split() {
+ Ultima::Shared::String s = "abc,def,,aaa,";
+ Ultima::Shared::StringArray a = s.split(',');
+ // Note: final empty string is trimmed
+ TS_ASSERT_EQUALS(a.size(), 4);
+ TS_ASSERT_EQUALS(a[1], "def");
+ TS_ASSERT_EQUALS(a[2], "");
+
+ Ultima::Shared::String s2 = "e,";
+ a = s.split(s2);
+ TS_ASSERT_EQUALS(a.size(), 5);
+ TS_ASSERT_EQUALS(a[1], "d");
+ TS_ASSERT_EQUALS(a[2], "f");
+ }
+};
diff --git a/test/engines/ultima/ultima8/misc/box.h b/test/engines/ultima/ultima8/misc/box.h
new file mode 100644
index 0000000000..c6da553336
--- /dev/null
+++ b/test/engines/ultima/ultima8/misc/box.h
@@ -0,0 +1,53 @@
+#include <cxxtest/TestSuite.h>
+#include "engines/ultima/ultima8/misc/box.h"
+/**
+ * Test suite for the functions in engines/ultima/ultima8/misc/box.h
+ */
+
+class U8BoxTestSuite : public CxxTest::TestSuite {
+ public:
+ U8BoxTestSuite() {
+ }
+
+ void test_simple_box() {
+ Ultima::Ultima8::Box box;
+ TS_ASSERT(!box.InBox(0,0,1));
+ TS_ASSERT(!box.InBox(0,1,0));
+ TS_ASSERT(!box.InBox(1,0,0));
+ box.ResizeRel(1,1,1);
+ TS_ASSERT(!box.InBox(-1,0,0));
+ TS_ASSERT(!box.InBox(0,-1,0));
+ TS_ASSERT(!box.InBox(0,0,-1));
+ TS_ASSERT(box.Overlaps(box));
+ TS_ASSERT(box == box);
+ box.ResizeRel(1,1,1);
+ TS_ASSERT(box.IsValid());
+ TS_ASSERT(box.Overlaps(box));
+ TS_ASSERT(box == box);
+ // TODO: All these tests are disabled becasue the box uses reversed
+ // coordinates in x and y.. need to confirm if that's the correct
+ // behavior
+ /*
+ TS_ASSERT(box.InBox(0,0,1));
+ TS_ASSERT(box.InBox(0,1,0));
+ TS_ASSERT(box.InBox(1,0,0));
+ box.MoveRel(0, 0, 1);
+ TS_ASSERT(!box.InBox(0,0,1));
+ TS_ASSERT(box.InBox(0,0,2));
+
+ Ultima::Ultima8::Box box2(box);
+ TS_ASSERT(box == box2);
+ TS_ASSERT(box.Overlaps(box2));
+ TS_ASSERT(box2 == box);
+ TS_ASSERT(box2.Overlaps(box));
+
+ Ultima::Ultima8::Box box3(0, 0, 0, 2, 2, 3);
+ TS_ASSERT(!(box2 == box3));
+ TS_ASSERT(box2.Overlaps(box3));
+ TS_ASSERT(box3.Overlaps(box2));
+ box3.ResizeAbs(1,2,2);
+ TS_ASSERT(!box3.Overlaps(box2));
+ */
+ }
+
+};
diff --git a/test/engines/ultima/ultima8/misc/id_man.h b/test/engines/ultima/ultima8/misc/id_man.h
new file mode 100644
index 0000000000..8b80fc256c
--- /dev/null
+++ b/test/engines/ultima/ultima8/misc/id_man.h
@@ -0,0 +1,42 @@
+#include <cxxtest/TestSuite.h>
+#include "engines/ultima/ultima8/misc/id_man.h"
+
+/**
+ * Test suite for the functions in engines/ultima/ultima8/misc/id_man.h
+ */
+
+class U8IdManTestSuite : public CxxTest::TestSuite {
+
+ public:
+ U8IdManTestSuite() {
+ }
+
+ void test_trim_spaces() {
+ Ultima::Ultima8::idMan idman = Ultima::Ultima8::idMan(1234, 5678);
+ TS_ASSERT(!idman.isFull());
+ TS_ASSERT(!idman.isIDUsed(1234));
+
+ uint16 newid = idman.getNewID();
+ TS_ASSERT_EQUALS(newid, 1234);
+ TS_ASSERT(idman.isIDUsed(1234));
+
+ bool reserved = idman.reserveID(1234);
+ TS_ASSERT(!reserved);
+ reserved = idman.reserveID(1235);
+ TS_ASSERT(reserved);
+ TS_ASSERT(idman.isIDUsed(1235));
+ uint16 newid2 = idman.getNewID();
+ TS_ASSERT_EQUALS(newid2, 1236);
+ TS_ASSERT(idman.isIDUsed(1236));
+
+ bool reserved2 = idman.reserveID(2000);
+ TS_ASSERT(reserved2);
+ TS_ASSERT(idman.isIDUsed(2000));
+
+ idman.clearAll();
+ idman.setNewMax(2001);
+ TS_ASSERT(!idman.isFull());
+ TS_ASSERT(!idman.isIDUsed(2000));
+ TS_ASSERT(!idman.isIDUsed(1234));
+ }
+};
diff --git a/test/engines/ultima/ultima8/misc/memset_n.h b/test/engines/ultima/ultima8/misc/memset_n.h
new file mode 100644
index 0000000000..a633f100e2
--- /dev/null
+++ b/test/engines/ultima/ultima8/misc/memset_n.h
@@ -0,0 +1,95 @@
+#include <cxxtest/TestSuite.h>
+#include "engines/ultima/ultima8/misc/memset_n.h"
+
+/**
+ * Test suite for the functions in engines/ultima/ultima8/misc/memset_n.h
+ */
+
+class U8MemsetTestSuite : public CxxTest::TestSuite {
+
+ static const uint32 VAL32 = 0xDEADBEEF;
+ static const uint32 VAL16 = 0xFEED;
+
+ uint8 buffer[256];
+
+ public:
+ U8MemsetTestSuite() {
+ }
+
+ static uint32 uint32val(const uint8 *p) {
+ return *reinterpret_cast<const uint32 *>(p);
+ }
+
+ static uint16 uint16val(const uint8 *p) {
+ return *reinterpret_cast<const uint16 *>(p);
+ }
+
+ void clear_buffer() {
+ memset(buffer, 0, 256);
+ }
+
+ void test_memset_32() {
+ // Pointer with some padding so we can make sure it does the right
+ // thing at start and end of memory block
+ uint8 *b = buffer + 16;
+
+ // Check a few alignments to make sure it does the right thing
+ // Starting alignment is not important as we cycle through them all
+ for (int i = 0; i < 10; i++) {
+ b++;
+ clear_buffer();
+ Ultima::Ultima8::memset_32(b, VAL32, 1);
+ TS_ASSERT_EQUALS(uint32val(b), VAL32);
+ TS_ASSERT_EQUALS(uint32val(b+4), 0);
+ TS_ASSERT_EQUALS(uint32val(b-4), 0);
+
+ clear_buffer();
+ Ultima::Ultima8::memset_32(b, VAL32, 2);
+ TS_ASSERT_EQUALS(uint32val(b), VAL32);
+ TS_ASSERT_EQUALS(uint32val(b+4), VAL32);
+ TS_ASSERT_EQUALS(uint32val(b+8), 0);
+ TS_ASSERT_EQUALS(uint32val(b-4), 0);
+ }
+ }
+
+ void test_memset_16() {
+ // Pointer with some padding so we can make sure it does the right
+ // thing at start and end of memory block
+ uint8 *b = buffer + 16;
+
+ // Check a few alignments to make sure it does the right thing
+ // Starting alignment is not important as we cycle through them all
+ for (int i = 0; i < 10; i++) {
+ b++;
+ clear_buffer();
+ Ultima::Ultima8::memset_16(b, VAL16, 1);
+ TS_ASSERT_EQUALS(uint16val(b), VAL16);
+ TS_ASSERT_EQUALS(uint16val(b+2), 0);
+ TS_ASSERT_EQUALS(uint16val(b-2), 0);
+
+ clear_buffer();
+ Ultima::Ultima8::memset_16(b, VAL16, 2);
+ TS_ASSERT_EQUALS(uint16val(b), VAL16);
+ TS_ASSERT_EQUALS(uint16val(b+2), VAL16);
+ TS_ASSERT_EQUALS(uint16val(b+4), 0);
+ TS_ASSERT_EQUALS(uint16val(b-2), 0);
+
+ clear_buffer();
+ Ultima::Ultima8::memset_16(b, VAL16, 3);
+ TS_ASSERT_EQUALS(uint16val(b), VAL16);
+ TS_ASSERT_EQUALS(uint16val(b+2), VAL16);
+ TS_ASSERT_EQUALS(uint16val(b+4), VAL16);
+ TS_ASSERT_EQUALS(uint16val(b+6), 0);
+ TS_ASSERT_EQUALS(uint16val(b-2), 0);
+
+ clear_buffer();
+ Ultima::Ultima8::memset_16(b, VAL16, 4);
+ TS_ASSERT_EQUALS(uint16val(b), VAL16);
+ TS_ASSERT_EQUALS(uint16val(b+2), VAL16);
+ TS_ASSERT_EQUALS(uint16val(b+4), VAL16);
+ TS_ASSERT_EQUALS(uint16val(b+6), VAL16);
+ TS_ASSERT_EQUALS(uint16val(b+8), 0);
+ TS_ASSERT_EQUALS(uint16val(b-2), 0);
+ }
+ }
+};
diff --git a/test/engines/ultima/ultima8/misc/util.h b/test/engines/ultima/ultima8/misc/util.h
new file mode 100644
index 0000000000..68dee04f5a
--- /dev/null
+++ b/test/engines/ultima/ultima8/misc/util.h
@@ -0,0 +1,87 @@
+#include <cxxtest/TestSuite.h>
+#include "engines/ultima/shared/std/string.h"
+#include "engines/ultima/ultima8/misc/util.h"
+
+/**
+ * Test suite for the functions in engines/ultima/ultima8/misc/util.h
+ */
+
+class U8UtilTestSuite : public CxxTest::TestSuite {
+
+ public:
+ U8UtilTestSuite() {
+ }
+
+ void test_trim_spaces() {
+ Ultima::Std::string s0 = " ";
+ Ultima::Ultima8::TrimSpaces(s0);
+ TS_ASSERT_EQUALS(s0, Ultima::Std::string(""));
+
+ Ultima::Std::string s1 = " abc ";
+ Ultima::Ultima8::TrimSpaces(s1);
+ TS_ASSERT_EQUALS(s1, Ultima::Std::string("abc"));
+
+ Ultima::Std::string s2 = "def";
+ Ultima::Ultima8::TrimSpaces(s2);
+ TS_ASSERT_EQUALS(s2, "def");
+ }
+
+ void test_tabs_to_spaces() {
+ Ultima::Std::string s1 = "\tabc \t ";
+ Ultima::Ultima8::TabsToSpaces(s1, 1);
+ TS_ASSERT_EQUALS(s1, " abc ");
+
+ Ultima::Std::string s2 = "def";
+ Ultima::Ultima8::TabsToSpaces(s2, 1);
+ TS_ASSERT_EQUALS(s2, "def");
+ }
+
+ void test_split_string() {
+ Ultima::Std::string s1 = "abc,def";
+ Ultima::Std::vector<Ultima::Std::string> v1;
+ Ultima::Ultima8::SplitString(s1, ',', v1);
+
+ TS_ASSERT_EQUALS(v1.size(), 2);
+ TS_ASSERT_EQUALS(v1[0], "abc");
+ TS_ASSERT_EQUALS(v1[1], "def");
+
+ Ultima::Std::string s2;
+ Ultima::Std::vector<Ultima::Std::string> v2;
+ Ultima::Ultima8::SplitString(s2, ',', v1);
+ TS_ASSERT_EQUALS(v1.size(), 0);
+
+ Ultima::Std::string s3 = " aa bb ";
+ Ultima::Ultima8::SplitString(s3, ' ', v1);
+ TS_ASSERT_EQUALS(v1.size(), 6);
+ TS_ASSERT_EQUALS(v1[0], "");
+ TS_ASSERT_EQUALS(v1[1], "aa");
+ }
+
+ void test_argv_to_string() {
+ // FIXME: It would be nicer if this function didn't leave a trailing space
+ Ultima::Std::vector<Ultima::Std::string> v;
+ Ultima::Std::string s;
+ Ultima::Ultima8::ArgvToString(v, s);
+ TS_ASSERT_EQUALS(s, "");
+
+ v.push_back("abc");
+ v.push_back("\t\nescape me \"!");
+ Ultima::Ultima8::ArgvToString(v, s);
+ TS_ASSERT_EQUALS(s, "abc \\t\\nescape\\ me\\ \\\"! ");
+ }
+
+ void test_string_to_argv() {
+ Ultima::Std::string s = "";
+ Ultima::Std::vector<Ultima::Std::string> v;
+ Ultima::Ultima8::StringToArgv(s, v);
+ TS_ASSERT_EQUALS(v.size(), 0);
+
+ // Test it strips leading space on args, and includes spaces inside ""s
+ s = "abc \\t\\nescape \"\\ me\\ \\\" !\" ";
+ Ultima::Ultima8::StringToArgv(s, v);
+ TS_ASSERT_EQUALS(v.size(), 3);
+ TS_ASSERT_EQUALS(v[0], "abc");
+ TS_ASSERT_EQUALS(v[1], "escape");
+ TS_ASSERT_EQUALS(v[2], " me \" !");
+ }
+};
diff --git a/test/engines/ultima/ultima8/usecode/bit_set.h b/test/engines/ultima/ultima8/usecode/bit_set.h
new file mode 100644
index 0000000000..511aba11f3
--- /dev/null
+++ b/test/engines/ultima/ultima8/usecode/bit_set.h
@@ -0,0 +1,35 @@
+#include <cxxtest/TestSuite.h>
+#include "engines/ultima/ultima8/usecode/bit_set.h"
+/**
+ * Test suite for the functions in engines/ultima/ultima8/usecode/bit_set.h
+ */
+
+class U8BitSetTestSuite : public CxxTest::TestSuite {
+ public:
+ Ultima::Ultima8::BitSet bs;
+
+ U8BitSetTestSuite() {
+ bs.setSize(0x1000);
+ }
+
+ void test_set_get() {
+ // Test with bit pattern in second byte of 01110100
+ // (pos goes from low bit to high bit)
+ bs.setBits(10, 5, 0x1D);
+ TS_ASSERT_EQUALS(bs.getBits(10, 5), 0x1D);
+ TS_ASSERT_EQUALS(bs.getBits(10, 4), 0xD);
+ TS_ASSERT_EQUALS(bs.getBits(8, 6), 0xD << 2);
+ TS_ASSERT_EQUALS(bs.getBits(8, 7), 0x1D << 2);
+ TS_ASSERT_EQUALS(bs.getBits(8, 8), 0x1D << 2);
+ TS_ASSERT_EQUALS(bs.getBits(14, 2), 0x1);
+ TS_ASSERT_EQUALS(bs.getBits(16, 32), 0);
+ TS_ASSERT_EQUALS(bs.getBits(0, 10), 0);
+ }
+
+ void test_clear() {
+ bs.setBits(10, 5, 0x15);
+ bs.setSize(0x1000);
+ TS_ASSERT_EQUALS(bs.getBits(10, 5), 0);
+ TS_ASSERT_EQUALS(bs.getBits(0, 32), 0);
+ }
+};
diff --git a/test/engines/ultima/ultima8/usecode/uc_list.h b/test/engines/ultima/ultima8/usecode/uc_list.h
new file mode 100644
index 0000000000..3342cabb78
--- /dev/null
+++ b/test/engines/ultima/ultima8/usecode/uc_list.h
@@ -0,0 +1,36 @@
+#include <cxxtest/TestSuite.h>
+#include "engines/ultima/ultima8/usecode/uc_list.h"
+/**
+ * Test suite for the functions in engines/ultima/ultima8/usecode/uc_list.h
+ */
+
+class U8UCListTestSuite : public CxxTest::TestSuite {
+ public:
+ U8UCListTestSuite() {
+ }
+
+ void test_static_list() {
+ Ultima::Ultima8::UCList l(2);
+
+ TS_ASSERT_EQUALS(l.getSize(), 0);
+ TS_ASSERT_EQUALS(l.getElementSize(), 2);
+
+ uint16 test = 0xBEEF;
+ l.append((uint8*)&test);
+ TS_ASSERT_EQUALS(l.getSize(), 1);
+
+ uint16 test2 = 0xF00D;
+ l.append((uint8*)&test2);
+ TS_ASSERT_EQUALS(l.getSize(), 2);
+ TS_ASSERT(l.inList((uint8*)&test));
+
+ l.remove((uint8*)&test);
+ TS_ASSERT(!l.inList((uint8*)&test));
+ TS_ASSERT(l.inList((uint8*)&test2));
+ TS_ASSERT_EQUALS(l.getSize(), 1);
+
+ l.free();
+ TS_ASSERT_EQUALS(l.getSize(), 0);
+ }
+
+};
diff --git a/test/engines/ultima/ultima8/usecode/uc_stack.h b/test/engines/ultima/ultima8/usecode/uc_stack.h
new file mode 100644
index 0000000000..9f34bb5b83
--- /dev/null
+++ b/test/engines/ultima/ultima8/usecode/uc_stack.h
@@ -0,0 +1,44 @@
+#include <cxxtest/TestSuite.h>
+#include "engines/ultima/ultima8/usecode/uc_stack.h"
+/**
+ * Test suite for the functions in engines/ultima/ultima8/usecode/uc_stack.h
+ */
+
+class U8UCStackTestSuite : public CxxTest::TestSuite {
+ public:
+ U8UCStackTestSuite() {
+ }
+
+ void test_static_stack() {
+ Ultima::Ultima8::UCStack stack;
+ test_for_stack(stack);
+ }
+
+ void test_dynamic_stack() {
+ Ultima::Ultima8::DynamicUCStack stack;
+ Ultima::Ultima8::DynamicUCStack stack2(32);
+ TS_ASSERT_EQUALS(stack2.getSize(), 32);
+ test_for_stack(stack);
+ test_for_stack(stack2);
+ }
+
+ private:
+ void test_for_stack(Ultima::Ultima8::BaseUCStack &s) {
+ TS_ASSERT_EQUALS(s.stacksize(), 0);
+ s.push4(0xDEADBEEF);
+ TS_ASSERT_EQUALS(s.stacksize(), 4);
+ TS_ASSERT_EQUALS(s.pop2(), 0xBEEF);
+ TS_ASSERT_EQUALS(s.pop2(), 0xDEAD);
+ s.push1(0xFE);
+ TS_ASSERT_EQUALS(s.stacksize(), 1);
+ s.push1(0xED);
+ s.push2(0xC0DE);
+ TS_ASSERT_EQUALS(s.pop2(), 0xC0DE);
+ TS_ASSERT_EQUALS(s.pop2(), 0xFEED);
+ TS_ASSERT_EQUALS(s.stacksize(), 0);
+ TS_ASSERT_EQUALS(s.getSP(), s.getSize());
+ s.push4(0xCAFEF00D);
+ TS_ASSERT_EQUALS(s.getSP(), s.getSize()-4);
+ }
+
+};
diff --git a/test/module.mk b/test/module.mk
index 9e844fa42d..057bd7a42b 100644
--- a/test/module.mk
+++ b/test/module.mk
@@ -13,6 +13,11 @@ ifeq ($(ENABLE_WINTERMUTE), STATIC_PLUGIN)
TEST_LIBS += engines/wintermute/libwintermute.a
endif
+ifeq ($(ENABLE_ULTIMA), STATIC_PLUGIN)
+ TESTS += $(srcdir)/test/engines/ultima/*/*/*.h
+ TEST_LIBS += engines/ultima/libultima.a
+endif
+
#
TEST_FLAGS := --runner=StdioPrinter --no-std --no-eh --include=$(srcdir)/test/cxxtest_mingw.h
TEST_CFLAGS := $(CFLAGS) -I$(srcdir)/test/cxxtest
More information about the Scummvm-git-logs
mailing list