Переглянути джерело

Adding ownership tests for const_propogating_ptr, const_ptr, copy_ptr.
Adding deep-equals test for copy_ptr copying.

Samuel Jaffe 9 роки тому
батько
коміт
b3f3d5bfd7
3 змінених файлів з 46 додано та 0 видалено
  1. 13 0
      const_propogating_ptr.t.h
  2. 13 0
      const_ptr.t.h
  3. 20 0
      copy_ptr.t.h

+ 13 - 0
const_propogating_ptr.t.h

@@ -31,4 +31,17 @@ public:
     const_propogating_ptr< ptr_t > const cp { p };
     TS_ASSERT( cp->is_const() );
   }
+  
+  void test_do_not_own() const {
+    bool has_delete{false};
+    struct test_t {
+      ~test_t() { _r = true; }
+      bool & _r;
+    };
+    test_t * test_struct = new test_t{has_delete};
+    const_propogating_ptr<test_t *>{test_struct};
+    TS_ASSERT_EQUALS(has_delete, false);
+    delete test_struct;
+    TS_ASSERT_EQUALS(has_delete, true);
+  }
 };

+ 13 - 0
const_ptr.t.h

@@ -40,4 +40,17 @@ public:
     TS_ASSERT( ! cpp->is_const() );
     TS_ASSERT( cp->is_const() );
   }
+  
+  void test_do_not_own() const {
+    bool has_delete{false};
+    struct test_t {
+      ~test_t() { _r = true; }
+      bool & _r;
+    };
+    test_t * test_struct = new test_t{has_delete};
+    const_ptr<test_t *>{test_struct};
+    TS_ASSERT_EQUALS(has_delete, false);
+    delete test_struct;
+    TS_ASSERT_EQUALS(has_delete, true);
+  }
 };

+ 20 - 0
copy_ptr.t.h

@@ -42,6 +42,15 @@ public:
     TS_ASSERT_DIFFERS( c1.get(), c2.get() );
   }
   
+  void test_copy_object_is_deep_equals() {
+    using vec_t = std::vector<int>;
+    vec_t my_vec = { 1, 3, 5, 3, 6, 1, 2, -1, 0 };
+    copy_ptr<vec_t> c1{ new vec_t{ my_vec } };
+    TS_ASSERT_EQUALS( *c1, my_vec );
+    copy_ptr<vec_t> c2{ c1 };
+    TS_ASSERT_EQUALS( *c2, *c1 );
+  }
+  
   void test_clone_polymorpic_object() {
     using ptr_t = clone_ptr<base, &base::clone>;
     ptr_t c0 { new derived_0 };
@@ -49,4 +58,15 @@ public:
     ptr_t c1 { new derived_1 };
     TS_ASSERT_EQUALS( ptr_t( c1 )->id(), derived_1::ID);
   }
+  
+  void test_does_own() const {
+    bool has_delete{false};
+    struct test_t {
+      ~test_t() { _r = true; }
+      bool & _r;
+    };
+    test_t * test_struct = new test_t{has_delete};
+    copy_ptr<test_t, nullptr>{ std::move(test_struct) };
+    TS_ASSERT_EQUALS(has_delete, true);
+  }
 };