Daniele Bartolini 13 лет назад
Родитель
Сommit
8ff46ba785
2 измененных файлов с 51 добавлено и 1 удалено
  1. 2 1
      tests/CMakeLists.txt
  2. 49 0
      tests/strings.cpp

+ 2 - 1
tests/CMakeLists.txt

@@ -4,13 +4,13 @@ project(tests)
 
 link_directories(${CROWN_BINARY_DIR})
 
-#link_libraries()
 add_executable(allocators allocators.cpp)
 add_executable(containers containers.cpp)
 add_executable(messages messages.cpp)
 add_executable(compressors compressors.cpp)
 add_executable(connections connections.cpp)
 add_executable(streams streams.cpp)
+add_executable(strings strings.cpp)
 add_executable(paths paths.cpp)
 
 
@@ -20,4 +20,5 @@ target_link_libraries(messages crown)
 target_link_libraries(compressors crown)
 target_link_libraries(connections crown)
 target_link_libraries(streams crown)
+target_link_libraries(strings crown)
 target_link_libraries(paths crown)

+ 49 - 0
tests/strings.cpp

@@ -0,0 +1,49 @@
+#include "String.h"
+#include <cassert>
+#include <stdio.h>
+
+using namespace crown;
+
+const char* hello_string = "/h.ello.everybody.stri/ng";
+const char* path_string = "/home/project/texture.tga";
+
+int main()
+{
+	// Test strlen
+	assert(string::strlen("ciao") == 4);
+	// FIXME add UTF-8 test case
+
+	// Test begin/end
+	assert(string::begin(hello_string) == &hello_string[0]);
+	
+	assert(string::end(hello_string) == &hello_string[24] + 2);
+	
+	// Test find_first/find_last
+	assert(string::find_first(hello_string, '.') == &hello_string[2]);
+	
+	assert(string::find_last(hello_string, '.') == &hello_string[17]);
+	
+	assert(string::find_first(hello_string, '?') == string::end(hello_string));
+	
+	assert(string::find_last(hello_string, '?') == string::end(hello_string));
+	
+	assert(string::find_last(hello_string, '/') == &hello_string[22]);
+	
+	assert(string::find_last(path_string, '/') == &path_string[13]);
+	
+	// Test substring
+	char string_buffer[64];
+	
+	memset(string_buffer, 'a', 64);
+	string::substring(string::begin(hello_string), string::end(hello_string), string_buffer, 64);
+	assert(string::strcmp(hello_string, string_buffer) == 0);
+	
+	memset(string_buffer, 'a', 64);
+	string::substring(string::begin(hello_string), &hello_string[11], string_buffer, 64);
+	assert(string::strcmp(string_buffer, "/h.ello.eve") == 0);
+	
+	memset(string_buffer, 'a', 64);
+	string::substring(string::begin(hello_string), string::end(hello_string), string_buffer, 5);
+	assert(string::strcmp(string_buffer, "/h.el") == 0);
+}
+