/** * A tracked_ptr compared with T or void* for equality with each other should be equal * if the pointer are equal. * They should be different, when their pointer are different. * * REM: This is no < or > comparison, since this is needed in the contain * i.e. in the registry we are currently using... */ TEST(TrackedPointer, EqualityWithPointer) { MyClass* bar = new MyClass(); MyClass* foo = new MyClass(); tracked_ptr<MyClass> bar_p(bar); // a wrapper for another pointer tracked_ptr<MyClass> foo_p(foo); // this is the basic assumption, independent of any test-framework specifics ASSERT_TRUE (bar_p == bar); ASSERT_FALSE(bar_p != bar); ASSERT_FALSE(bar_p == foo); ASSERT_TRUE (bar_p != foo_p); // the EQ and NE macros introduce const quantifiers a long the way // so that has to work, too. ASSERT_EQ(bar_p, bar); ASSERT_NE(bar_p, foo); ASSERT_EQ(foo_p, foo); ASSERT_NE(foo_p, bar); // and now make sure everything works with a void* and NULL, too //void* bar_v = bar; //ASSERT_EQ(bar_p, bar_v); ASSERT_NE(bar_p, NULL); //ASSERT_NE(foo_p, bar_v); foo_p = NULL; ASSERT_EQ(foo_p, NULL); delete bar; delete foo; }
/** * Two tracked_ptr compared for equality with each other should be equal * if the wrapped pointer are equal. * They should be different, when their wrapped pointer are different. * * REM: This is no < or > comparison, since this is needed in the contain * i.e. in the registry we are currently using... */ TEST(TrackedPointer, Equality) { MyClass* bar = new MyClass(); MyClass* foo = new MyClass(); // two wrapper for the same pointer tracked_ptr<MyClass> bar_p(bar); tracked_ptr<MyClass> bar_p2(bar); // a wrapper for another pointer tracked_ptr<MyClass> foo_p(foo); // this is the basic assumption, independent of any test-framework specifics ASSERT_TRUE (bar_p == bar_p2); ASSERT_FALSE(bar_p != bar_p2); ASSERT_FALSE(bar_p == foo_p); ASSERT_TRUE (bar_p != foo_p); // the EQ and NE macros introduce const quantifiers a long the way // so that has to work, too. ASSERT_EQ(bar_p, bar_p2); ASSERT_NE(bar_p, foo_p); delete bar; delete foo; }
int main (void) { foo (); foo_p (); bar (); check_ptr_eq (&foo, &foo_alias); return 0; }
int main() { Parent p; foo_p(&p); Child c; foo_c(&c); foo_p(&c); SuperChild s; foo_s(&s); foo_c(&s); foo_p(&s); p.x; p.y; p.f0(); c.z; c.x; c.y; c.f0(); c.f1(); c.f2(); c.f3(); s.z2; s.z; s.x; s.y; s.f0(); s.f1(); s.f2(); s.f3(); s.f4(); s.f5(); s.f6(); return 0; }
/** * The getter function */ TEST(TrackedPointer, Getter) { MyClass* bar = new MyClass(); MyClass* foo = new MyClass(); // two wrapper for the same pointer tracked_ptr<MyClass> bar_p(bar); tracked_ptr<MyClass> bar_p2(bar); // a wrapper for another pointer tracked_ptr<MyClass> foo_p(foo); ASSERT_EQ(bar, bar_p.get()); ASSERT_EQ(bar, bar_p2.get()); ASSERT_EQ(foo, foo_p.get()); delete bar; delete foo; }