提交 6b85b325 编写于 作者: 邹晓航

add cow_ptr test

上级 8e5f9a47
#ifndef _COWPTR_IMPL_H_
#define _COWPTR_IMPL_H_
namespace TinySTL{
template<class T>
cow_ptr<T>::cow_ptr(T *p = nullptr) :ptr_(p){}
template<class T>
template<class D>
cow_ptr<T>::cow_ptr(T *p, D d) : ptr_(p, d){}
template<class T>
cow_ptr<T>::cow_ptr(const cow_ptr& cp){
ptr_ = cp.ptr_;
}
template<class T>
cow_ptr<T>& cow_ptr<T>::operator = (const cow_ptr& cp){
if (this != &cp){
ptr_.decrease_ref();
ptr_ = cp.ptr_;
}
return *this;
}
template<class T>
typename cow_ptr<T>::element_type cow_ptr<T>::operator *()const{
return *ptr_;
}
template<class T>
typename cow_ptr<T>::element_type *cow_ptr<T>::operator ->()const{
return ptr_.operator->();
}
}
#endif
\ No newline at end of file
#include "COWPtrTest.h"
#include "../String.h"
namespace TinySTL{
namespace COWPtrTest{
void testCase1(){
cow_ptr<string> cp1(new string("hello"));
assert(*cp1 == "hello");
cp1->append(" world");
auto cp2 = cp1;
assert(*cp2 == "hello world");
cow_ptr<string> cp3;
cp3 = cp1;
assert(*cp3 == "hello world");
}
void testAllCases(){
testCase1();
}
}
}
\ No newline at end of file
#ifndef _COWPTR_TEST_H_
#define _COWPTR_TEST_H_
#include "../COWPtr.h"
#include <cassert>
namespace TinySTL{
namespace COWPtrTest{
void testCase1();
void testAllCases();
}
}
#endif
\ No newline at end of file
......@@ -82,7 +82,7 @@
<ItemGroup>
<ClCompile Include="Detail\Alloc.cpp" />
<ClCompile Include="Detail\String.cpp" />
<ClCompile Include="Detail\TireTree.cpp" />
<ClCompile Include="Detail\TrieTree.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="Profiler\Profiler.cpp" />
<ClCompile Include="Test\AlgorithmTest.cpp" />
......@@ -90,6 +90,7 @@
<ClCompile Include="Test\BinarySearchTreeTest.cpp" />
<ClCompile Include="Test\BitmapTest.cpp" />
<ClCompile Include="Test\CircularBufferTest.cpp" />
<ClCompile Include="Test\COWPtrTest.cpp" />
<ClCompile Include="Test\DequeTest.cpp" />
<ClCompile Include="Test\GraphTest.cpp" />
<ClCompile Include="Test\ListTest.cpp" />
......@@ -115,11 +116,13 @@
<ClInclude Include="Bitmap.h" />
<ClInclude Include="CircularBuffer.h" />
<ClInclude Include="Construct.h" />
<ClInclude Include="COWPtr.h" />
<ClInclude Include="Deque.h" />
<ClInclude Include="Detail\AVLTree.impl.h" />
<ClInclude Include="Detail\BinarySearchTree.impl.h" />
<ClInclude Include="Detail\Bitmap.impl.h" />
<ClInclude Include="Detail\CircularBuffer.impl.h" />
<ClInclude Include="Detail\COWPtr.impl.h" />
<ClInclude Include="Detail\Deque.impl.h" />
<ClInclude Include="Detail\Graph.impl.h" />
<ClInclude Include="Detail\List.impl.h" />
......@@ -142,6 +145,7 @@
<ClInclude Include="Test\BinarySearchTreeTest.h" />
<ClInclude Include="Test\BitmapTest.h" />
<ClInclude Include="Test\CircularBufferTest.h" />
<ClInclude Include="Test\COWPtrTest.h" />
<ClInclude Include="Test\DequeTest.h" />
<ClInclude Include="Test\GraphTest.h" />
<ClInclude Include="Test\ListTest.h" />
......
......@@ -90,9 +90,6 @@
<ClCompile Include="Test\GraphTest.cpp">
<Filter>Test</Filter>
</ClCompile>
<ClCompile Include="Detail\TireTree.cpp">
<Filter>Detail</Filter>
</ClCompile>
<ClCompile Include="Test\TrieTreeTest.cpp">
<Filter>Test</Filter>
</ClCompile>
......@@ -105,6 +102,12 @@
<ClCompile Include="Test\SharedPtrTest.cpp">
<Filter>Test</Filter>
</ClCompile>
<ClCompile Include="Detail\TrieTree.cpp">
<Filter>Detail</Filter>
</ClCompile>
<ClCompile Include="Test\COWPtrTest.cpp">
<Filter>Test</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="TypeTraits.h">
......@@ -278,6 +281,15 @@
<ClInclude Include="Test\SharedPtrTest.h">
<Filter>Test</Filter>
</ClInclude>
<ClInclude Include="COWPtr.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Detail\COWPtr.impl.h">
<Filter>Detail</Filter>
</ClInclude>
<ClInclude Include="Test\COWPtrTest.h">
<Filter>Test</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\README.md" />
......
......@@ -8,6 +8,7 @@
#include "Test\BitmapTest.h"
#include "Test\BinarySearchTreeTest.h"
#include "Test\CircularBufferTest.h"
#include "Test\COWPtrTest.h"
#include "Test\DequeTest.h"
#include "Test\GraphTest.h"
#include "Test\ListTest.h"
......@@ -32,6 +33,7 @@ int main(){
TinySTL::BitmapTest::testAllCases();
TinySTL::BinarySearchTreeTest::testAllCases();
TinySTL::CircularBufferTest::testAllCases();
TinySTL::COWPtrTest::testAllCases();
TinySTL::DequeTest::testAllCases();
TinySTL::ListTest::testAllCases();
TinySTL::GraphTest::testAllCases();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册