MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / pointer_test

Function pointer_test

unittests/boxed_cast_test.cpp:257–292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255
256template<typename T>
257bool pointer_test(const T& default_value, const T& new_value)
258{
259 T *p = new T(default_value);
260
261 // we store a pointer to a pointer, so we can get a pointer to a pointer
262 try {
263 T **result = boxed_cast<T **>(var(&p));
264 *(*result) = new_value;
265
266
267 if (p != (*result) ) {
268 std::cerr << "Pointer passed in different than one returned\n";
269 delete p;
270 return false;
271 }
272
273 if (*p != *(*result) ) {
274 std::cerr << "Somehow dereferenced pointer values are not the same?\n";
275 delete p;
276 return false;
277 }
278
279 delete p;
280 return true;
281 } catch (const exception::bad_boxed_cast &) {
282 std::cerr << "Bad boxed cast performing ** to ** test\n";
283 delete p;
284 return false;
285 } catch (...) {
286 std::cerr << "Unknown exception performing ** to ** test\n";
287 delete p;
288 return false;
289 }
290
291
292}
293
294
295int main()

Callers

nothing calls this directly

Calls 1

varFunction · 0.85

Tested by

no test coverage detected