Explorar o código

Add unit tests directory

Daniele Bartolini %!s(int64=13) %!d(string=hai) anos
pai
achega
1deaf7eff3
Modificáronse 3 ficheiros con 69 adicións e 0 borrados
  1. 12 0
      tests/CMakeLists.txt
  2. 22 0
      tests/allocators.cpp
  3. 35 0
      tests/containers.cpp

+ 12 - 0
tests/CMakeLists.txt

@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(tests)
+
+link_directories(${CROWN_BINARY_DIR})
+
+#link_libraries()
+add_executable(allocators allocators.cpp)
+add_executable(containers containers.cpp)
+
+target_link_libraries(allocators crown)
+target_link_libraries(containers crown)

+ 22 - 0
tests/allocators.cpp

@@ -0,0 +1,22 @@
+#include "Allocator.h"
+#include "MallocAllocator.h"
+#include <cstdio>
+#include <cassert>
+
+using namespace crown;
+
+int main()
+{
+	MallocAllocator malloc_allocator;
+
+	char* char_buffer = (char*)malloc_allocator.allocate(128);
+	assert(malloc_allocator.get_allocated_size() >= 128);
+
+	printf("MallocAllocator::get_allocated_size(): %d", malloc_allocator.get_allocated_size());
+
+	malloc_allocator.deallocate(char_buffer);
+
+	printf("MallocAllocator::get_allocated_size(): %d", malloc_allocator.get_allocated_size());
+	//assert(malloc_allocator.get_allocated_size() == 0);
+}
+

+ 35 - 0
tests/containers.cpp

@@ -0,0 +1,35 @@
+#include "List.h"
+#include "Array.h"
+#include <cstdio>
+#include <cassert>
+
+using namespace crown;
+
+int main()
+{
+	List<int> int_list;
+
+	assert(int_list.size() == 0);
+
+	int_list.push_back(10);
+	int_list.push_back(20);
+	int_list.push_back(30);
+	int_list.push_back(40);
+	int_list.push_back(50);
+	int_list.push_back(60);
+
+	assert(int_list.size() == 6);
+	assert(*int_list.begin() == 10);
+	assert(*int_list.end() == 60);
+
+	int_list.pop_back();
+
+	assert(int_list.size() == 5);
+	assert(*int_list.begin() == 10);
+	assert(*int_list.end() == 50);
+
+	int_list.clear();
+
+	assert(int_list.size() == 0);
+}
+