From 6f22300491b25946a64c0db8ae8a21059528c124 Mon Sep 17 00:00:00 2001 From: Casper Hornstrup Date: Tue, 4 Jan 2005 21:29:09 +0000 Subject: [PATCH] Add project and module tests. svn path=/branches/xmlbuildsystem/; revision=12801 --- reactos/tools/rbuild/makefile | 4 +- reactos/tools/rbuild/rbuild.cpp | 3 +- reactos/tools/rbuild/test.h | 23 +++++++++-- reactos/tools/rbuild/tests/alltests.cpp | 44 +++++++++++++++++++-- reactos/tools/rbuild/tests/data/module.xml | 14 +++++++ reactos/tools/rbuild/tests/data/project.xml | 10 +++++ reactos/tools/rbuild/tests/moduletest.cpp | 14 ++++++- reactos/tools/rbuild/tests/projecttest.cpp | 8 ++++ 8 files changed, 109 insertions(+), 11 deletions(-) create mode 100644 reactos/tools/rbuild/tests/data/module.xml create mode 100644 reactos/tools/rbuild/tests/data/project.xml create mode 100644 reactos/tools/rbuild/tests/projecttest.cpp diff --git a/reactos/tools/rbuild/makefile b/reactos/tools/rbuild/makefile index 8a0ae32ff24..6ed0f4cd28a 100644 --- a/reactos/tools/rbuild/makefile +++ b/reactos/tools/rbuild/makefile @@ -13,7 +13,9 @@ BASE_OBJECTS = \ OBJECTS = $(BASE_OBJECTS) rbuild.o -TESTS = tests/moduletest.o +TESTS = \ + tests/moduletest.o \ + tests/projecttest.o TEST_OBJECTS = $(BASE_OBJECTS) $(TESTS) tests/alltests.o diff --git a/reactos/tools/rbuild/rbuild.cpp b/reactos/tools/rbuild/rbuild.cpp index 51fff9beb77..722289f6ad2 100644 --- a/reactos/tools/rbuild/rbuild.cpp +++ b/reactos/tools/rbuild/rbuild.cpp @@ -58,7 +58,8 @@ main ( int argc, char** argv ) } catch (Exception& ex) { - printf ( ex.Message.c_str() ); + printf ( "%s\n", + ex.Message.c_str() ); return 1; } } diff --git a/reactos/tools/rbuild/test.h b/reactos/tools/rbuild/test.h index a598c5ba58c..fd50f514147 100644 --- a/reactos/tools/rbuild/test.h +++ b/reactos/tools/rbuild/test.h @@ -14,18 +14,26 @@ protected: void Assert(const char *message, ...); void IsTrue(bool condition, const char* file, - int line ); + int line); void IsFalse(bool condition, const char* file, - int line ); + int line); void AreEqual(int expected, int actual, const char* file, - int line ); + int line); + void AreEqual(string expected, + string actual, + const char* file, + int line); + void AreEqual(const char* expected, + string actual, + const char* file, + int line); void AreNotEqual(int expected, int actual, const char* file, - int line ); + int line); private: void Fail(); }; @@ -35,6 +43,13 @@ private: #define ARE_EQUAL(expected,actual) AreEqual(expected,actual,__FILE__,__LINE__) #define ARE_NOT_EQUAL(expected,actual) AreNotEqual(expected,actual,__FILE__,__LINE__) +class ProjectTest : public BaseTest +{ +public: + void Run(); +}; + + class ModuleTest : public BaseTest { public: diff --git a/reactos/tools/rbuild/tests/alltests.cpp b/reactos/tools/rbuild/tests/alltests.cpp index 4a3287bf56b..04aa80146c5 100644 --- a/reactos/tools/rbuild/tests/alltests.cpp +++ b/reactos/tools/rbuild/tests/alltests.cpp @@ -4,7 +4,7 @@ BaseTest::BaseTest() { - Failed = true; + Failed = false; } BaseTest::~BaseTest() @@ -61,6 +61,32 @@ void BaseTest::AreEqual(int expected, } } +void BaseTest::AreEqual(string expected, + string actual, + const char* file, + int line) +{ + if (actual != expected) + { + Assert("Expected '%s' was '%s' at %s:%d\n", + expected.c_str(), + actual.c_str(), + file, + line); + } +} + +void BaseTest::AreEqual(const char* expected, + string actual, + const char* file, + int line) +{ + AreEqual(string(expected), + actual, + file, + line); +} + void BaseTest::AreNotEqual(int expected, int actual, const char* file, @@ -103,10 +129,19 @@ public: GetTests(tests); for (size_t i = 0; i < tests.size(); i++) { - BaseTest& test = *tests[i]; - test.Run(); - if (test.Failed) + try + { + BaseTest& test = *tests[i]; + test.Run(); + if (test.Failed) + numberOfFailedTests++; + } + catch (Exception& ex) + { + printf("%s\n", + ex.Message.c_str()); numberOfFailedTests++; + } } if (numberOfFailedTests > 0) @@ -119,6 +154,7 @@ public: private: void GetTests ( BaseTestList& tests ) { + tests.push_back(new ProjectTest()); tests.push_back(new ModuleTest()); } }; diff --git a/reactos/tools/rbuild/tests/data/module.xml b/reactos/tools/rbuild/tests/data/module.xml new file mode 100644 index 00000000000..19eb169058a --- /dev/null +++ b/reactos/tools/rbuild/tests/data/module.xml @@ -0,0 +1,14 @@ + + + + file1.c + file2.c + + + + + file3.c + file4.c + + + diff --git a/reactos/tools/rbuild/tests/data/project.xml b/reactos/tools/rbuild/tests/data/project.xml new file mode 100644 index 00000000000..f43930a4cc3 --- /dev/null +++ b/reactos/tools/rbuild/tests/data/project.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/reactos/tools/rbuild/tests/moduletest.cpp b/reactos/tools/rbuild/tests/moduletest.cpp index 4e7f0f2d75d..c707bf7c631 100644 --- a/reactos/tools/rbuild/tests/moduletest.cpp +++ b/reactos/tools/rbuild/tests/moduletest.cpp @@ -2,5 +2,17 @@ void ModuleTest::Run() { - IS_TRUE(false); + string projectFilename ( "tests/data/module.xml" ); + Project* project = new Project( projectFilename ); + ARE_EQUAL(2, project->modules.size()); + + Module& module1 = *project->modules[0]; + ARE_EQUAL(2, module1.files.size()); + ARE_EQUAL("./dir1/file1.c", module1.files[0]->name); + ARE_EQUAL("./dir1/file2.c", module1.files[1]->name); + + Module& module2 = *project->modules[1]; + ARE_EQUAL(2, module2.files.size()); + ARE_EQUAL("./dir2/file3.c", module2.files[0]->name); + ARE_EQUAL("./dir2/file4.c", module2.files[1]->name); } diff --git a/reactos/tools/rbuild/tests/projecttest.cpp b/reactos/tools/rbuild/tests/projecttest.cpp new file mode 100644 index 00000000000..c53dd504522 --- /dev/null +++ b/reactos/tools/rbuild/tests/projecttest.cpp @@ -0,0 +1,8 @@ +#include "test.h" + +void ProjectTest::Run() +{ + string projectFilename ( "tests/data/project.xml" ); + Project* project = new Project( projectFilename ); + ARE_EQUAL(2, project->modules.size()); +}