aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/utility/factory_test.cpp
blob: 98ef2b0479e9e10ee4bdb1c3275f262d7b249f9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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;
}