From 7ba10619aa4bee952fb5dba974128774f5b5bb04 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 2 Sep 2013 00:57:33 +0200 Subject: [PATCH] draft unit test to cover the basic render job properties --- src/backend/engine/job.h | 12 ++ tests/46engine.tests | 4 + tests/core/backend/engine/dummy-job.hpp | 16 ++- tests/core/backend/engine/job-hash-test.cpp | 110 ++++++++++++++++++ .../engine/scheduler-interface-test.cpp | 2 +- 5 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 tests/core/backend/engine/job-hash-test.cpp diff --git a/src/backend/engine/job.h b/src/backend/engine/job.h index fd46a4152..41dda27e6 100644 --- a/src/backend/engine/job.h +++ b/src/backend/engine/job.h @@ -274,6 +274,18 @@ namespace engine { friend lib::HashVal hash_value (Job const&); }; + inline bool + operator== (Job const& left, Job const& right) + { + return hash_value (left) == hash_value (right); + } + + inline bool + operator!= (Job const& left, Job const& right) + { + return hash_value (left) != hash_value (right); + } + diff --git a/tests/46engine.tests b/tests/46engine.tests index 9e188a4c7..f63f41317 100644 --- a/tests/46engine.tests +++ b/tests/46engine.tests @@ -43,6 +43,10 @@ PLANNED "Frame Dispatcher Interface" DispatcherInterface_test < + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ + + +#include "lib/test/run.hpp" +#include "lib/util.hpp" + +#include "backend/real-clock.hpp" +#include "backend/engine/dummy-job.hpp" + + +namespace backend { +namespace engine { +namespace test { + + using util::isSameObject; + + + + + /*************************************************************************** + * @test verify the basic properties of the job and job descriptor struct; + * especially verify that job data is passed properly back to the + * closure and that a identity can be constructed based on a + * hash of the job's data. + * + * @see Job + * @see JobClosure + * @see SchedulerInterface_test + */ + class JobHash_test : public Test + { + + virtual void + run (Arg) + { + verify_simple_job_properties(); + verify_job_identity(); + } + + + void + verify_simple_job_properties() + { + Job job = DummyJob::build(); + CHECK (job.isValid()); + + Time beforeInvocation = RealClock::now(); + job.triggerJob(); + + CHECK (DummyJob::was_invoked (job)); + CHECK (RealClock::now() > DummyJob::invocationTime (job)); + CHECK (beforeInvocation < DummyJob::invocationTime (job)); + } + + + void + verify_job_identity() + { + Job job1 = DummyJob::build(); + Job job2 = DummyJob::build(); + + CHECK (job1 != job2, "random test data clash"); + + CHECK (hash_value(job1) != hash_value(job2)); + + Job copy(job1); + CHECK (!isSameObject (job1, copy)); + + CHECK (copy == job1); + CHECK (hash_value(job1) == hash_value(copy)); + + copy.parameter.nominalTime++; + CHECK (hash_value(job1) != hash_value(copy)); + + copy = job1; + copy.parameter.invoKey.metaInfo.a++; + CHECK (hash_value(job1) != hash_value(copy)); + + copy = job1; + DummyClosure dummyClosure; + copy.jobClosure = &dummyClosure; + CHECK (hash_value(job1) != hash_value(copy)); + } + }; + + + /** Register this test class... */ + LAUNCHER(JobHash_test, "unit engine"); + +}}} // namespace backend::engine::test diff --git a/tests/core/backend/engine/scheduler-interface-test.cpp b/tests/core/backend/engine/scheduler-interface-test.cpp index 0057cc9e2..d1fcc3518 100644 --- a/tests/core/backend/engine/scheduler-interface-test.cpp +++ b/tests/core/backend/engine/scheduler-interface-test.cpp @@ -190,6 +190,6 @@ namespace test { /** Register this test class... */ - LAUNCHER(SchedulerInterface_test, "unit common"); + LAUNCHER(SchedulerInterface_test, "unit engine"); }}} // namespace backend::engine::test