~sophie-middleton08/maus/devel

« back to all changes in this revision

Viewing changes to tests/cpp_unit/JsonCppProcessors/ObjectProcessorTest.cc

  • Committer: Chris Rogers
  • Date: 2013-04-30 15:29:46 UTC
  • mfrom: (659.1.64 release-candidate)
  • Revision ID: chris.rogers@stfc.ac.uk-20130430152946-7xe8q7zwcn3a4uhs
Tags: MAUS-v0.5.2
MAUS-v0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
    req_proc.RegisterPointerBranch("branch_b", &double_proc, &TestObject::GetB,
57
57
                                                      &TestObject::SetB, true);
58
58
    req_proc.RegisterConstantBranch("branch_c", Json::Value("const"), true);
 
59
    req_proc.RegisterIgnoredBranch("branch_d", true);
59
60
 
60
61
    not_req_proc.RegisterValueBranch("branch_a", &double_proc,
61
62
                                   &TestObject::GetA, &TestObject::SetA, false);
62
63
    not_req_proc.RegisterPointerBranch("branch_b", &double_proc,
63
64
                                   &TestObject::GetB, &TestObject::SetB, false);
64
65
    not_req_proc.RegisterConstantBranch("branch_c", Json::Value("const"), false);
 
66
    not_req_proc.RegisterIgnoredBranch("branch_d", false);
65
67
    test.SetA(1.);
66
68
    test.SetB(new double(2.));
67
69
  }
109
111
  json_object["branch_a"] = Json::Value(1.);
110
112
  json_object["branch_b"] = Json::Value(2.);
111
113
  json_object["branch_c"] = Json::Value("const");
 
114
  json_object["branch_d"] = Json::Value(1.); // could be int, string or anything
112
115
 
113
116
  // should handle processing correctly
114
117
  TestObject* cpp_object = req_proc.JsonToCpp(json_object);
120
123
  json_object["branch_a"] = Json::Value(1.);
121
124
  json_object["branch_b"] = Json::Value();
122
125
  json_object["branch_c"] = Json::Value("const");
 
126
  json_object["branch_d"] = Json::Value("const");
123
127
  EXPECT_THROW(req_proc.JsonToCpp(json_object), Squeal);
124
128
 
125
129
  // should throw if object is missing
126
130
  Json::Value json_object_missing_a(Json::objectValue);
127
131
  json_object_missing_a["branch_b"] = Json::Value(2.);
128
132
  json_object_missing_a["branch_c"] = Json::Value("const");
 
133
  json_object_missing_a["branch_d"] = Json::Value("const");
129
134
  EXPECT_THROW(req_proc.JsonToCpp(json_object_missing_a), Squeal);
130
135
 
131
136
  Json::Value json_object_missing_b(Json::objectValue);
132
137
  json_object_missing_b["branch_a"] = Json::Value(2.);
133
138
  json_object_missing_b["branch_c"] = Json::Value("const");
 
139
  json_object_missing_b["branch_d"] = Json::Value("const");
134
140
  EXPECT_THROW(req_proc.JsonToCpp(json_object_missing_b), Squeal);
135
141
 
136
142
  Json::Value json_object_missing_c(Json::objectValue);
137
143
  json_object_missing_c["branch_a"] = Json::Value(2.);
138
144
  json_object_missing_c["branch_b"] = Json::Value(1.);
 
145
  json_object_missing_c["branch_d"] = Json::Value("const");
139
146
  EXPECT_THROW(req_proc.JsonToCpp(json_object_missing_c), Squeal);
140
147
 
 
148
  Json::Value json_object_missing_d(Json::objectValue);
 
149
  json_object_missing_d["branch_a"] = Json::Value(1.);
 
150
  json_object_missing_d["branch_b"] = Json::Value();
 
151
  json_object_missing_d["branch_c"] = Json::Value("const");
 
152
  EXPECT_THROW(req_proc.JsonToCpp(json_object_missing_d), Squeal);
 
153
 
141
154
  // should throw if object is present but can't be processed
142
155
  json_object["branch_b"] = Json::Value("string");
143
156
  EXPECT_THROW(req_proc.JsonToCpp(json_object), Squeal);
156
169
  json_object["branch_a"] = Json::Value(1.);
157
170
  json_object["branch_b"] = Json::Value(2.);
158
171
  json_object["branch_c"] = Json::Value("const");
 
172
  json_object["branch_d"] = Json::Value("const");
159
173
 
160
174
  // should handle processing correctly
161
175
  TestObject* cpp_object = not_req_proc.JsonToCpp(json_object);
164
178
  delete cpp_object;
165
179
 
166
180
  // should not throw if object is missing
167
 
  Json::Value json_object_missing_a(Json::objectValue);
168
 
  json_object_missing_a["branch_b"] = Json::Value(2.);
169
 
  json_object_missing_a["branch_c"] = Json::Value("const");
170
 
  cpp_object = not_req_proc.JsonToCpp(json_object_missing_a);
171
 
  delete cpp_object;
172
 
 
173
 
  Json::Value json_object_missing_b(Json::objectValue);
174
 
  json_object_missing_b["branch_a"] = Json::Value(2.);
175
 
  json_object_missing_a["branch_c"] = Json::Value("const");
176
 
  cpp_object = not_req_proc.JsonToCpp(json_object_missing_b);
177
 
  delete cpp_object;
178
 
 
179
 
  Json::Value json_object_missing_c(Json::objectValue);
180
 
  json_object_missing_b["branch_a"] = Json::Value(2.);
181
 
  json_object_missing_a["branch_b"] = Json::Value(1.);
182
 
  cpp_object = not_req_proc.JsonToCpp(json_object_missing_c);
 
181
  Json::Value json_object_missing_all(Json::objectValue);
 
182
  cpp_object = not_req_proc.JsonToCpp(json_object_missing_all);
183
183
  delete cpp_object;
184
184
 
185
185
  // should throw if object is present but can't be processed