aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/utility/factory_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'meowpp/utility/factory_test.cpp')
-rw-r--r--meowpp/utility/factory_test.cpp161
1 files changed, 161 insertions, 0 deletions
diff --git a/meowpp/utility/factory_test.cpp b/meowpp/utility/factory_test.cpp
new file mode 100644
index 0000000..98ef2b0
--- /dev/null
+++ b/meowpp/utility/factory_test.cpp
@@ -0,0 +1,161 @@
+#define MEOWPP_UTILITY_FACTORY_TESTING
+
+#include <cstdio>
+
+#include <meowpp/utility/factory.h>
+#include <meowpp/utility/factory.h>
+#include <meowpp/utility/factory.h>
+#include <meowpp/utility/factory.h>
+
+#include <meowpp/debug/assert.h>
+
+#include <meowpp/utility/object.h>
+#include <meowpp/utility/operation.h>
+
+
+namespace meow {
+
+class FactoryTest {
+ private:
+ int f() { return 123; }
+ class Oper1 : public Operation {
+ public:
+ Oper1() : Operation(2, 4) {}
+ State Operate(Pointer<Object const> const* inputs,
+ Pointer<Object> const* outputs) const {
+ Int32 a = *(Int32 const*)inputs[0].address();
+ Int32 b = *(Int32 const*)inputs[1].address();
+ outputs[0]->CopyFrom(&a);
+ outputs[1]->CopyFrom(&b);
+ outputs[2]->CopyFrom(&b);
+ outputs[3]->CopyFrom(&a);
+ return (a < b ? 0 : 1);
+ }
+ };
+ public:
+ FactoryTest() {
+ Pointer<Int32>* in = new Pointer<Int32>[2];
+ Pointer<Int32 const>* out = new Pointer<Int32 const>[4];
+ Pointer<Object const>* in2 = new Pointer<Object const>[2];
+ Pointer<Object>* out2 = new Pointer<Object>[4];
+ for (int i = 0; i < 2; ++i) {
+ in[i] = Pointer<Int32>(new Int32, SINGLE, true);
+ in2[i] = Pointer<Object const>(in[i].address(), SINGLE, false);
+ }
+ for (int i = 0; i < 4; ++i) {
+ out[i] = Pointer<Int32 const>(new Int32, SINGLE, true);
+ out2[i] = Pointer<Object>(
+ const_cast<Int32*>(out[i].address()), SINGLE, false);
+ }
+ fprintf(stderr, "aaaaaaaaa\n");
+ Oper1 op;
+ int kk;
+ kk = f();
+ fprintf(stderr, "kk = %d\n", kk);
+ fprintf(stderr, "mid0\n");
+ {
+ Factory f1(Pointer<Operation const>(&op, SINGLE, false),
+ Pointer<Pointer<Object const>>(in2, ARRAY, false),
+ Pointer<Pointer<Object>>(out2, ARRAY, false),
+ false);
+ Assert(f1.operation() == &op, "");
+ *in[0] = 3;
+ *in[1] = 5;
+ kk = static_cast<int>(f1.Update());
+ Assert(kk == 0, "");
+ Assert(*in[0] == 3, "");
+ Assert(*in[1] == 5, "");
+ Assert(*out[0] == 3, "");
+ Assert(*out[1] == 5, "");
+ Assert(*out[2] == 5, "");
+ Assert(*out[3] == 3, "");
+ Assert(f1.HasRedo() == true, "");
+ Assert(f1.operation() == &op, "");
+ *in[0] = 7;
+ *in[1] = 5;
+ kk = static_cast<int>(f1.Update());
+ Assert(kk == 1, "");
+ Assert(*in[0] == 7, "");
+ Assert(*in[1] == 5, "");
+ Assert(*out[0] == 7, "");
+ Assert(*out[1] == 5, "");
+ Assert(*out[2] == 5, "");
+ Assert(*out[3] == 7, "");
+ Assert(f1.HasRedo() == true, "");
+ Assert(f1.operation() == &op, "");
+ *in[0] = 7;
+ *in[1] = 5;
+ kk = static_cast<int>(f1.Update());
+ Assert(kk == 1, "");
+ Assert(*in[0] == 7, "");
+ Assert(*in[1] == 5, "");
+ Assert(*out[0] == 7, "");
+ Assert(*out[1] == 5, "");
+ Assert(*out[2] == 5, "");
+ Assert(*out[3] == 7, "");
+ Assert(f1.HasRedo() == true, "");
+ Assert(f1.operation() == &op, "");
+ fprintf(stderr, "hi!!\n");
+ }
+ fprintf(stderr, "====\n");
+ {
+ Factory f2(Pointer<Operation const>(&op, SINGLE, false),
+ Pointer<Pointer<Object const>>(in2, ARRAY, false),
+ Pointer<Pointer<Object>>(out2, ARRAY, false),
+ true);
+ Assert(f2.operation() == &op, "");
+ Assert(f2.HasRedo() == false, "");
+ *in[0] = 3;
+ *in[1] = 5;
+ kk = static_cast<int>(f2.Update());
+ Assert(f2.HasRedo() == true, "");
+ Assert(kk == 0, "kk = %d\n", kk);
+ Assert(*in[0] == 3, "");
+ Assert(*in[1] == 5, "");
+ Assert(*out[0] == 3, "");
+ Assert(*out[1] == 5, "");
+ Assert(*out[2] == 5, "");
+ Assert(*out[3] == 3, "");
+ Assert(f2.operation() == &op, "");
+ *in[0] = 7;
+ *in[1] = 5;
+ kk = static_cast<int>(f2.Update());
+ Assert(f2.HasRedo() == true, "");
+ Assert(kk == 1, "");
+ Assert(*in[0] == 7, "");
+ Assert(*in[1] == 5, "");
+ Assert(*out[0] == 7, "");
+ Assert(*out[1] == 5, "");
+ Assert(*out[2] == 5, "");
+ Assert(*out[3] == 7, "");
+ Assert(f2.operation() == &op, "");
+ *in[0] = 7;
+ *in[1] = 5;
+ kk = static_cast<int>(f2.Update());
+ Assert(f2.HasRedo() == false, "");
+ Assert(kk == 1, "");
+ Assert(*in[0] == 7, "");
+ Assert(*in[1] == 5, "");
+ Assert(*out[0] == 7, "");
+ Assert(*out[1] == 5, "");
+ Assert(*out[2] == 5, "");
+ Assert(*out[3] == 7, "");
+ Assert(f2.operation() == &op, "");
+ fprintf(stderr, "hi\n");
+ }
+ fprintf(stderr, "mid\n");
+
+ delete [] in;
+ delete [] out;
+ delete [] in2;
+ delete [] out2;
+ fprintf(stderr, "hj\n");
+ }
+} _;
+
+}
+
+int main() {
+ return 0;
+}
+