From 1f0005c4e269ec8d9b848b85e40ab11d7d67a979 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 10 Jul 2016 13:05:30 +0200 Subject: DIRECTOR: Lingo: Initial code for Lingo test suite. Uses special game target --- engines/director/detection.cpp | 1 + engines/director/detection_tables.h | 14 +++ engines/director/director.cpp | 158 ++------------------------ engines/director/director.h | 3 +- engines/director/lingo/lingo.cpp | 20 ++++ engines/director/lingo/lingo.h | 2 + engines/director/lingo/tests/goto.lingo | 5 + engines/director/lingo/tests/if.lingo | 20 ++++ engines/director/lingo/tests/lingotests.lingo | 0 engines/director/lingo/tests/loops.lingo | 22 ++++ engines/director/lingo/tests/macros.lingo | 55 +++++++++ engines/director/lingo/tests/math.lingo | 12 ++ engines/director/lingo/tests/mci.lingo | 2 + engines/director/lingo/tests/strings.lingo | 13 +++ 14 files changed, 175 insertions(+), 152 deletions(-) create mode 100644 engines/director/lingo/tests/goto.lingo create mode 100644 engines/director/lingo/tests/if.lingo create mode 100644 engines/director/lingo/tests/lingotests.lingo create mode 100644 engines/director/lingo/tests/loops.lingo create mode 100644 engines/director/lingo/tests/macros.lingo create mode 100644 engines/director/lingo/tests/math.lingo create mode 100644 engines/director/lingo/tests/mci.lingo create mode 100644 engines/director/lingo/tests/strings.lingo (limited to 'engines/director') diff --git a/engines/director/detection.cpp b/engines/director/detection.cpp index 97b5014685..b0fea292a5 100644 --- a/engines/director/detection.cpp +++ b/engines/director/detection.cpp @@ -67,6 +67,7 @@ bool DirectorEngine::hasFeature(EngineFeature f) const { static const PlainGameDescriptor directorGames[] = { { "director", "Macromedia Director Game" }, + { "directortest", "Macromedia Director Test Target" }, { "gundam0079", "Gundam 0079: The War for Earth" }, { "jewels", "Jewels of the Oracle" }, { "jman", "The Journeyman Project" }, diff --git a/engines/director/detection_tables.h b/engines/director/detection_tables.h index d242b878be..8c9c9f17e9 100644 --- a/engines/director/detection_tables.h +++ b/engines/director/detection_tables.h @@ -26,6 +26,20 @@ namespace Director { static const DirectorGameDescription gameDescriptions[] = { + { + { + "directortest", + "", + AD_ENTRY1("lingotests.lingo", 0), + Common::EN_ANY, + Common::kPlatformWindows, + ADGF_NO_FLAGS, + GUIO1(GUIO_NOASPECT) + }, + GID_TEST, + 3 + }, + { { "gundam0079", diff --git a/engines/director/director.cpp b/engines/director/director.cpp index bbd7916a41..58a5459602 100644 --- a/engines/director/director.cpp +++ b/engines/director/director.cpp @@ -104,158 +104,14 @@ Common::Error DirectorEngine::run() { _lingo = new Lingo(this); _soundManager = new DirectorSound(); -#if 0 - _mainArchive = nullptr; - _currentScore = nullptr; - - _lingo->addCode("--\n\ - set x = 1\n\ - if x = 5 then exit\n\ - else put 10.0\n\ - repeat with x = 1 to 5\n\ - if x = 3 then put 30\n\ - else if x = 4 then put 40\n\ - else if x = 5 then put 50\n\ - else put 10.0\n\ - if x = 1 then\n\ - put 1\n\ - else if x = 2 then\n\ - put 1232.12345678901234\n\ - put 2.2\n\ - else if x = 3 then put 3\n\ - end if\n\ - if x = 4 then put 4\n\ - else put 5\n\ - end repeat\n\ - set z = \"foo bar baz\"\n\ - set z1 = z & \" meow\"\n\ - set z1 = z1 && \"woof\"\n\ - put z\n\ - put z1\n\ - put chars(\"Macromedia\", 6, 6)\n\ - put chars(\"Macromedia\", 6, 10)\n\ - put chars(\"Macromedia\", -1, 15)\n\ - if z1 contains \"Me\xafW\" then\n\ - put \"Contains\"\n\ - else\n\ - put \"Doesn't contain\"\n\ - end if\n\ -", kMovieScript, 2); - -_lingo->executeScript(kMovieScript, 2); - -return Common::kNoError; - - _lingo->addCode("--\n\ -macro SHIPX\n\ -global x, y\n\ -set x = Random(5)\n\ -if x = 1 then\n\ -go \"Zoom\"\n\ -exit\n\ -end if\n\ -if x >1 then\n\ -set y = 10\n\ -exit\n\ -end if\n\ -put 100\n\ -\n\ ---\n\ -macro ZIPX\n\ -set x = Random(5)\n\ -if x = 1 then\n\ -go \"ZIP\"\n\ -exit\n\ -end if\n\ -if x >1 then\n\ -put x\n\ -exit\n\ -end if\n\ -\n\ ---\n\ -macro check par1, par2 \n\ -, par3\n\ -if par1 = 3 then\n\ - put -3\n\ -else\n\ - put 0\n\ -end if \n\ -if par2 = 2 then \n\ - put 2 \n\ -else \n\ - put 0\n\ -end if\n\ -put par1\n\ -put par2\n\ -put par3\n\ -", kMovieScript, 1); - -_lingo->addCode("check(2, 3)\n\ -global x, y\n\ -set y = 8\n\ -shipx\n\ -put x\n\ -zipx\n\ -put x\n\ -put y\n\ -check(1, 2, 3)\n\ -check 4, 5, 6\n\ -check 7, 8\n\ -if random(4) > 2 then put 1000\n\ -set z = 5.5\n\ -set z1 = 2\n\ -set z2 = z / z1\n\ -put z\n\ -put z1\n\ -put z2\n\ -put integer(z2)\n\ -put cos(z2)\n\ -", kMovieScript, 2); - -_lingo->executeScript(kMovieScript, 2); - -return Common::kNoError; - - - _lingo->addCode("mci \"open MM\\T005045a.wav type WaveAudio alias T005045a\"\n\ - mci \"play T005045a from 22710 to 32872\"", kMovieScript, 1); - - _lingo->addCode("go to frame \"Open23\" of movie \"OpenCabin23\"\n\ -go \"CARDBACK\"\n\ -go movie \"BAR 1\"\n\ -go to \"Open23\" of movie \"OpenCabin23\"\n\ -go to \"Chair\"\n\ -set x = 2 + 3 * (4 / 2)\n\ -put x\n", kMovieScript, 2); - -_lingo->addCode("set x = 5\n\ -if x <= 5 then set x = 6 end if\n\ -if (x = 5) then\n\ - set x = 7 -- this is comment\n\ -else\n\ - set x = 8\n\ - -- this is another comment\n\ -end if\n\ -put x\n\ --- this is more comment\n\ -set y = 1\n\ -repeat while (y < 5)\n\ - set y = y + 1\n\ - put y\n\ -end repeat\n\ -\n\ -repeat with z = 10 to 15\n\ - put z\n\ -end repeat\n\ -repeat with y = 5 down to 1\n\ -put y\n\ -end repeat\n\ -", kMovieScript, 3); - - _lingo->executeScript(kMovieScript, 3); + if (getGameID() == GID_TEST) { + _mainArchive = nullptr; + _currentScore = nullptr; - return Common::kNoError; -#endif + _lingo->runTests(); + + return Common::kNoError; + } //FIXME _mainArchive = new RIFFArchive(); diff --git a/engines/director/director.h b/engines/director/director.h index bb08099fa6..0d4ffa7612 100644 --- a/engines/director/director.h +++ b/engines/director/director.h @@ -39,7 +39,8 @@ class MacResManager; namespace Director { enum DirectorGameID { - GID_GENERIC + GID_GENERIC, + GID_TEST }; class Archive; diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp index c1116247b9..26fdfc2edb 100644 --- a/engines/director/lingo/lingo.cpp +++ b/engines/director/lingo/lingo.cpp @@ -296,4 +296,24 @@ Common::String *Lingo::toLowercaseMac(Common::String *s) { return res; } +void Lingo::runTests() { + Common::File inFile; + Common::ArchiveMemberList fileList; + SearchMan.listMatchingMembers(fileList, "*.lingo"); + + int counter = 1; + + for (Common::ArchiveMemberList::iterator it = fileList.begin(); it != fileList.end(); ++it) { + Common::ArchiveMember const &m = **it; + Common::SeekableReadStream *const stream = m.createReadStream(); + if (stream) { + uint size = stream->size(); + + warning("Executing file %s of size %d", m.getName().c_str(), size); + } + + inFile.close(); + } +} + } // End of namespace Director diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h index d8cd64df0f..6aa7917ff4 100644 --- a/engines/director/lingo/lingo.h +++ b/engines/director/lingo/lingo.h @@ -144,6 +144,8 @@ public: Common::String *toLowercaseMac(Common::String *s); + void runTests(); + public: void execute(int pc); void pushContext(); diff --git a/engines/director/lingo/tests/goto.lingo b/engines/director/lingo/tests/goto.lingo new file mode 100644 index 0000000000..250ea24f8a --- /dev/null +++ b/engines/director/lingo/tests/goto.lingo @@ -0,0 +1,5 @@ +go to frame "Open23" of movie "OpenCabin23" +go "CARDBACK" +go movie "BAR 1" +go to "Open23" of movie "OpenCabin23" +go to "Chair" diff --git a/engines/director/lingo/tests/if.lingo b/engines/director/lingo/tests/if.lingo new file mode 100644 index 0000000000..c9bdacac52 --- /dev/null +++ b/engines/director/lingo/tests/if.lingo @@ -0,0 +1,20 @@ +-- +set x = 1 +if x = 5 then exit +else put 10.0 + +repeat with x = 1 to 5 + if x = 3 then put 30 + else if x = 4 then put 40 + else if x = 5 then put 50 + else put 10.0 + if x = 1 then + put 1 + else if x = 2 then + put 1232.12345678901234 + put 2.2 + else if x = 3 then put 3 + end if + if x = 4 then put 4 + else put 5 +end repeat diff --git a/engines/director/lingo/tests/lingotests.lingo b/engines/director/lingo/tests/lingotests.lingo new file mode 100644 index 0000000000..e69de29bb2 diff --git a/engines/director/lingo/tests/loops.lingo b/engines/director/lingo/tests/loops.lingo new file mode 100644 index 0000000000..0c7592a12a --- /dev/null +++ b/engines/director/lingo/tests/loops.lingo @@ -0,0 +1,22 @@ +set x = 5 +if x <= 5 then set x = 6 end if +if (x = 5) then +set x = 7 -- this is comment +else +set x = 8 +-- this is another comment +end if +put x +-- this is more comment +set y = 1 +repeat while (y < 5) +set y = y + 1 +put y +end repeat + +repeat with z = 10 to 15 +put z +end repeat +repeat with y = 5 down to 1 +put y +end repeat diff --git a/engines/director/lingo/tests/macros.lingo b/engines/director/lingo/tests/macros.lingo new file mode 100644 index 0000000000..9167f1dffb --- /dev/null +++ b/engines/director/lingo/tests/macros.lingo @@ -0,0 +1,55 @@ +-- +macro SHIPX +global x, y +set x = Random(5) +if x = 1 then +go \"Zoom\" +exit +end if +if x >1 then +set y = 10 +exit +end if +put 100 + +-- +macro ZIPX +set x = Random(5) +if x = 1 then +go \"ZIP\" +exit +end if +if x >1 then +put x +exit +end if + +-- +macro check par1, par2 +, par3 +if par1 = 3 then +put -3 +else +put 0 +end if +if par2 = 2 then +put 2 +else +put 0 +end if +put par1 +put par2 +put par3 +", kMovieScript, 1); + +_lingo->addCode("check(2, 3) +global x, y +set y = 8 +shipx +put x +zipx +put x +put y +check(1, 2, 3) +check 4, 5, 6 +check 7, 8 diff --git a/engines/director/lingo/tests/math.lingo b/engines/director/lingo/tests/math.lingo new file mode 100644 index 0000000000..d4b3d96105 --- /dev/null +++ b/engines/director/lingo/tests/math.lingo @@ -0,0 +1,12 @@ +if random(4) > 2 then put 1000 +set z = 5.5 +set z1 = 2 +set z2 = z / z1 +put z +put z1 +put z2 +put integer(z2) +put cos(z2) + +set x = 2 + 3 * (4 / 2) +put x diff --git a/engines/director/lingo/tests/mci.lingo b/engines/director/lingo/tests/mci.lingo new file mode 100644 index 0000000000..04130bf907 --- /dev/null +++ b/engines/director/lingo/tests/mci.lingo @@ -0,0 +1,2 @@ +mci "open MM\T005045a.wav type WaveAudio alias T005045a" +mci "play T005045a from 22710 to 32872" diff --git a/engines/director/lingo/tests/strings.lingo b/engines/director/lingo/tests/strings.lingo new file mode 100644 index 0000000000..568eb74640 --- /dev/null +++ b/engines/director/lingo/tests/strings.lingo @@ -0,0 +1,13 @@ +set z = "foo bar baz" +set z1 = z & " meow" +set z1 = z1 && "woof" +put z +put z1 +put chars("Macromedia", 6, 6) +put chars("Macromedia", 6, 10) +put chars("Macromedia", -1, 15) +if z1 contains "MeÍW" then + put "Contains" +else + put "Doesn't contain" +end if -- cgit v1.2.3