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)
5  2013, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 #include "lib/util.hpp"
21 
22 #include "vault/real-clock.hpp"
23 #include "vault/gear/job.h"
25 
26 #include <boost/functional/hash.hpp>
27 
28 
29 namespace steam {
30 namespace engine{
31 namespace test {
32 
33  using util::isSameObject;
34  using vault::gear::Job;
35  using vault::gear::JobParameter;
36 
37 
38 
39 
40  /**********************************************************************/
50  class JobHash_test : public Test
51  {
52 
53  virtual void
54  run (Arg)
55  {
56  seedRand();
57  verify_simple_job_properties();
58  verify_job_identity();
59  }
60 
61 
62  void
63  verify_simple_job_properties()
64  {
65  MockJob job;
66  Time beforeInvocation = RealClock::now();
67  job.triggerJob();
68 
69  CHECK (MockJob::was_invoked (job));
70  CHECK (RealClock::now() > MockJob::invocationTime (job));
71  CHECK (beforeInvocation < MockJob::invocationTime (job));
72  }
73 
74 
75  void
76  verify_job_identity()
77  {
78  MockJob job1;
79  MockJob job2;
80 
81  CHECK (job1 != job2, "random test data clash");
82 
83  CHECK (hash_value(job1) != hash_value(job2));
84 
85  Job copy(job1);
86  CHECK (!isSameObject (job1, copy));
87 
88  CHECK (copy == job1);
89  CHECK (hash_value(job1) == hash_value(copy));
90 
91  copy.parameter.nominalTime++;
92  CHECK (hash_value(job1) != hash_value(copy)); // hash value depends on the concrete nominal job time
93 
94  copy = job1;
95  copy.parameter.invoKey.part.a++;
96  CHECK (hash_value(job1) != hash_value(copy)); // hash value depends on the internal interpretation of the invocation key
97 
98 
99  class OtherClosure
100  : public JobClosure
101  {
102  void invokeJobOperation (JobParameter) { /* irrelevant */ }
103  JobKind getJobKind() const { return META_JOB; }
104  InvocationInstanceID buildInstanceID(HashVal) const { return InvocationInstanceID(); }
105 
106  size_t
107  hashOfInstance(InvocationInstanceID invoKey) const
108  {
109  return boost::hash_value (invoKey.part.a);
110  }
111  };
112  OtherClosure someOtherClosure;
113 
114  copy = job1;
115  copy.jobClosure = &someOtherClosure;
116  CHECK (hash_value(job1) != hash_value(copy)); // hash value indeed depends on the concrete job closure instance
117  }
118  };
119 
120 
122  LAUNCHER(JobHash_test, "unit engine");
123 
124 }}} // namespace steam::engine::test
Mock data structures to support implementation testing of render job planning and frame dispatch...
Definition: run.hpp:40
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:299
JobKind
Definition: job.h:62
Simplistic 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:103
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:52
Interface of the closure for frame rendering jobs.
Definition: job.h:235
render process self organisation
Definition: job.h:66
Individual frame rendering task, forwarding to a closure.
Definition: job.h:268
Front-end for simplified access to the current wall clock time.
HashVal hash_value(ProcID const &procID)
generate registry hash value based on the distinct data in ProcID.
Definition: proc-node.cpp:105
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee&#39;s memory identities. ...
Definition: util.hpp:421