Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Set-up google test.

Kishore Nalland2b903a93137
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 12c19312..01339f91 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,21 +1,67 @@
cmake_minimum_required(VERSION 2.8)
-project(search)
+project(typesense)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -O0")
+# Download and compile gtest -------------------------------------------------------------------------------------------
+if(NOT EXISTS ${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0)
+ set(GTEST_TAR_PATH ${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0.tar.gz)
+ message(STATUS "Downloading and extracting Google Test...")
+ file(DOWNLOAD https://github.com/google/googletest/archive/release-1.8.0.tar.gz ${GTEST_TAR_PATH})
+ execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvzf ${GTEST_TAR_PATH})
+ file(RENAME ${CMAKE_SOURCE_DIR}/googletest-release-1.8.0 ${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0)
+endif()
+
+if(NOT EXISTS ${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0/googletest/build)
+ message("Configuring Google Test...")
+ file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0/googletest/build)
+ execute_process(COMMAND ${CMAKE_COMMAND}
+ "-H${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0/googletest"
+ "-B${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0/googletest/build"
+ RESULT_VARIABLE
+ GOOGLETEST_CONFIGURE)
+ if(NOT GOOGLETEST_CONFIGURE EQUAL 0)
+ message(FATAL_ERROR "Google Test Configure failed!")
+ endif()
+
+ message("Building Google Test locally...")
+ execute_process(COMMAND ${CMAKE_COMMAND} --build
+ "${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0/googletest/build"
+ RESULT_VARIABLE
+ GOOGLETEST_BUILD)
+ if(NOT GOOGLETEST_BUILD EQUAL 0)
+ message(FATAL_ERROR "Google Test build failed!")
+ endif()
+endif()
+#-----------------------------------------------------------------------------------------------------------------------
+
+if (APPLE)
+ add_definitions(-DGTEST_USE_OWN_TR1_TUPLE)
+ add_definitions(-D__GLIBCXX__)
+ include_directories(/usr/local/opt/openssl/include) # For openssl installed with brew
+endif (APPLE)
+
# FIXME: Need to use find_package() to locate the correct openssl library
# FIXME: build libfor as part of the build process
FILE(GLOB HEADER_FILES include/*)
include_directories(include)
-include_directories(external/libfor)
-include_directories(/usr/local/opt/openssl/include)
+include_directories(${CMAKE_SOURCE_DIR}/external/libfor)
+include_directories(${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0/googletest/include)
+
+link_directories(${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0/googletest/build)
+add_executable(typesense_test test/forarray_test.cpp)
add_executable(search ${HEADER_FILES} src/art.cpp src/intersection.cpp src/main.cpp src/collection.cpp)
add_executable(typesense-server ${HEADER_FILES} src/art.cpp src/intersection.cpp src/collection.cpp src/server.cpp)
+target_link_libraries(typesense_test
+ ${CMAKE_SOURCE_DIR}/external/libfor/libfor.a
+ gtest gtest_main
+)
+
target_link_libraries(search ${CMAKE_SOURCE_DIR}/external/libfor/libfor.a rocksdb)
target_link_libraries(typesense-server
${CMAKE_SOURCE_DIR}/external/libfor/libfor.a
diff --git a/test/forarray_test.cpp b/test/forarray_test.cpp
new file mode 100644
index 00000000..3b38f913
--- /dev/null
+++ b/test/forarray_test.cpp
@@ -0,0 +1,19 @@
+#include <gtest/gtest.h>
+#include "forarray.h"
+
+TEST(ForarrayTest, AppendSorted) {
+ forarray arr;
+ const int SIZE = 10 * 1000;
+
+ EXPECT_EQ(arr.getLength(), 0);
+
+ for(uint32_t i=0; i < SIZE; i++) {
+ arr.append_sorted(i);
+ }
+
+ EXPECT_EQ(arr.getLength(), SIZE);
+
+ for(uint32_t i=0; i < SIZE; i++) {
+ EXPECT_EQ(arr.at(i), i);
+ }
+}
\ No newline at end of file