Lumiera  0.pre.03
»edit your freedom«
job-hash-test.cpp
Go to the documentation of this file.
1 /*
2  JobHash(Test) - verify job definition and job identity hash
3 
4  Copyright (C) Lumiera.org
5  2013, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 #include "lib/util.hpp"
30 
31 #include "vault/real-clock.hpp"
32 #include "vault/gear/job.h"
34 
35 #include <boost/functional/hash.hpp>
36 
37 
38 namespace steam {
39 namespace engine{
40 namespace test {
41 
42  using util::isSameObject;
43  using vault::gear::Job;
44  using vault::gear::JobParameter;
45 
46 
47 
48 
49  /**********************************************************************/
59  class JobHash_test : public Test
60  {
61 
62  virtual void
63  run (Arg)
64  {
65  verify_simple_job_properties();
66  verify_job_identity();
67  }
68 
69 
70  void
71  verify_simple_job_properties()
72  {
73  MockJob job;
74  Time beforeInvocation = RealClock::now();
75  job.triggerJob();
76 
77  CHECK (MockJob::was_invoked (job));
78  CHECK (RealClock::now() > MockJob::invocationTime (job));
79  CHECK (beforeInvocation < MockJob::invocationTime (job));
80  }
81 
82 
83  void
84  verify_job_identity()
85  {
86  MockJob job1;
87  MockJob job2;
88 
89  CHECK (job1 != job2, "random test data clash");
90 
91  CHECK (hash_value(job1) != hash_value(job2));
92 
93  Job copy(job1);
94  CHECK (!isSameObject (job1, copy));
95 
96  CHECK (copy == job1);
97  CHECK (hash_value(job1) == hash_value(copy));
98 
99  copy.parameter.nominalTime++;
100  CHECK (hash_value(job1) != hash_value(copy)); // hash value depends on the concrete nominal job time
101 
102  copy = job1;
103  copy.parameter.invoKey.part.a++;
104  CHECK (hash_value(job1) != hash_value(copy)); // hash value depends on the internal interpretation of the invocation key
105 
106 
107  class OtherClosure
108  : public JobClosure
109  {
110  void invokeJobOperation (JobParameter) { /* irrelevant */ }
111  JobKind getJobKind() const { return META_JOB; }
112  InvocationInstanceID buildInstanceID(HashVal) const { return InvocationInstanceID(); }
113 
114  size_t
115  hashOfInstance(InvocationInstanceID invoKey) const
116  {
117  return boost::hash_value (invoKey.part.a);
118  }
119  };
120  OtherClosure someOtherClosure;
121 
122  copy = job1;
123  copy.jobClosure = &someOtherClosure;
124  CHECK (hash_value(job1) != hash_value(copy)); // hash value indeed depends on the concrete job closure instance
125  }
126  };
127 
128 
130  LAUNCHER(JobHash_test, "unit engine");
131 
132 }}} // namespace steam::engine::test
Mock data structures to support implementation testing of render job planning and frame dispatch...
Definition: run.hpp:49
Mock setup for a render Job with NO action but built-in diagnostics.
Steam-Layer implementation namespace root.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
JobKind
Definition: job.h:71
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Definition of a render job.
opaque ID attached to each individual job invocation.
Definition: job.h:112
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:56
Interface of the closure for frame rendering jobs.
Definition: job.h:244
render process self organisation
Definition: job.h:75
Individual frame rendering task, forwarding to a closure.
Definition: job.h:277
Front-end for simplified access to the current wall clock time.
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.
Definition: util.hpp:372