COWPtrTest.cpp 525 字节
Newer Older
邹晓航 已提交
1 2 3 4 5 6 7 8 9
#include "COWPtrTest.h"

#include "../String.h"

namespace TinySTL{
	namespace COWPtrTest{
		void testCase1(){
			cow_ptr<string> cp1(new string("hello"));
			assert(*cp1 == "hello");
邹晓航 已提交
10
			assert(cp1);
邹晓航 已提交
11 12
			
			auto cp2 = cp1;
邹晓航 已提交
13
			assert(*cp2 == "hello");
邹晓航 已提交
14 15 16

			cow_ptr<string> cp3;
			cp3 = cp1;
邹晓航 已提交
17 18 19 20 21 22 23 24
			assert(*cp3 == "hello");

			assert(cp1.get() == cp2.get() && cp2.get() == cp3.get());

			assert(cp1 == cp2 && !(cp2 != cp3));

			cow_ptr<string> cp4;
			assert(cp4 == nullptr);
邹晓航 已提交
25 26 27 28 29 30 31
		}

		void testAllCases(){
			testCase1();
		}
	}
}