From a46481fde4eb6825960c0eb1ae302de3eedbc172 Mon Sep 17 00:00:00 2001 From: ilor <kailoran@gmail.com> Date: Thu, 4 Nov 2010 17:34:16 +0100 Subject: [PATCH] Add TSet to_string, some basic value tests, explicitly look for pwrutils, bump required versions --- CMakeScripts/FindPwrUtils.cmake | 43 +++++++++++++++++++++++++++++++++ libwccl/CMakeLists.txt | 7 ++++-- libwccl/values/tset.cpp | 11 +++++++++ libwccl/values/tset.h | 4 +++ tests/CMakeLists.txt | 5 ++-- tests/values.cpp | 28 +++++++++++++++++++++ 6 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 CMakeScripts/FindPwrUtils.cmake create mode 100644 tests/values.cpp diff --git a/CMakeScripts/FindPwrUtils.cmake b/CMakeScripts/FindPwrUtils.cmake new file mode 100644 index 0000000..62e25bb --- /dev/null +++ b/CMakeScripts/FindPwrUtils.cmake @@ -0,0 +1,43 @@ +FIND_PATH(PwrUtils_INCLUDE_DIR foreach.h /usr/include/libpwrutils /usr/local/include/libpwrutils ) + +FIND_LIBRARY(PwrUtils_LIBRARY NAMES pwrutils PATH /usr/lib /usr/local/lib) + +MARK_AS_ADVANCED(PwrUtils_LIBRARY) +MARK_AS_ADVANCED(PwrUtils_INCLUDE_DIR) + + +IF (PwrUtils_INCLUDE_DIR AND PwrUtils_LIBRARY) + SET(PwrUtils_FOUND TRUE) +ENDIF (PwrUtils_INCLUDE_DIR AND PwrUtils_LIBRARY) + +IF (PwrUtils_FOUND) + set(PwrUtils_VERSION 0.0.0) + FIND_FILE(_PwrUtils_VERSION_FILE version.h ${PwrUtils_INCLUDE_DIR}) + MARK_AS_ADVANCED(_PwrUtils_VERSION_FILE) + IF (_PwrUtils_VERSION_FILE) + FILE(READ ${_PwrUtils_VERSION_FILE} _PwrUtils_VERSION_CONENTS) + STRING(REGEX REPLACE ".*#define LIBPWRUTILS_VERSION \\\"([0-9.]+)\\\".*" "\\1" PwrUtils_VERSION "${_PwrUtils_VERSION_CONENTS}") + ENDIF (_PwrUtils_VERSION_FILE) + IF (PwrUtils_FIND_VERSION) + IF (PwrUtils_VERSION VERSION_LESS PwrUtils_FIND_VERSION) + IF (PwrUtils_FIND_REQUIRED) + MESSAGE(${_PwrUtils_VERSION_FILE}) + MESSAGE(FATAL_ERROR "PwrUtils version too old: ${PwrUtils_VERSION}, requested >= ${PwrUtils_FIND_VERSION}") + ELSE (PwrUtils_FIND_REQUIRED) + IF (NOT PwrUtils_FIND_QUIETLY) + MESSAGE(STATUS "PwrUtils version too old: ${PwrUtils_VERSION}, requested >= ${PwrUtils_FIND_VERSION}") + ENDIF (NOT PwrUtils_FIND_QUIETLY) + ENDIF (PwrUtils_FIND_REQUIRED) + set(PwrUtils_FOUND False) + ENDIF (PwrUtils_VERSION VERSION_LESS PwrUtils_FIND_VERSION) + ENDIF (PwrUtils_FIND_VERSION) + IF (NOT PwrUtils_FIND_QUIETLY) + MESSAGE(STATUS "Found libpwrutils ${PwrUtils_VERSION}: ${PwrUtils_LIBRARY}") + ENDIF (NOT PwrUtils_FIND_QUIETLY) +ELSE (PwrUtils_FOUND) + IF (PwrUtils_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find libpwrutils") + ELSE (PwrUtils_FIND_REQUIRED) + MESSAGE(STATUS "libpwrutils not found") + ENDIF (PwrUtils_FIND_REQUIRED) +ENDIF (PwrUtils_FOUND) diff --git a/libwccl/CMakeLists.txt b/libwccl/CMakeLists.txt index cdab23c..c7044f6 100644 --- a/libwccl/CMakeLists.txt +++ b/libwccl/CMakeLists.txt @@ -4,9 +4,12 @@ PROJECT(wccl) include_directories( ${CMAKE_CURRENT_BINARY_DIR}/include/ ) -find_package(Corpus2 0.1.0 REQUIRED) +find_package(Corpus2 0.1.1 REQUIRED) set(LIBS ${LIBS} ${Corpus2_LIBRARY}) +find_package(PwrUtils 0.0.3 REQUIRED) +set(LIBS ${LIBS} ${PwrUtils_LIBRARY}) + link_directories(${Boost_LIBRARY_DIRS}) set(LIBS ${LIBS} ${Boost_LIBRARIES}) @@ -26,7 +29,7 @@ SET(libwccl_STAT_SRC file(GLOB_RECURSE INCS "*.h") add_library(wccl SHARED ${libwccl_STAT_SRC} ${INCS}) -target_link_libraries ( wccl ${LIBS} pwrutils) +target_link_libraries ( wccl ${LIBS} ) set_target_properties(wccl PROPERTIES VERSION "${ver_major}.${ver_minor}" diff --git a/libwccl/values/tset.cpp b/libwccl/values/tset.cpp index 41aec52..9573bcb 100644 --- a/libwccl/values/tset.cpp +++ b/libwccl/values/tset.cpp @@ -1,7 +1,18 @@ #include <libwccl/values/tset.h> +#include <sstream> namespace Wccl { const char* TSet::type_name = "TSet"; +std::string TSet::to_raw_string() const +{ + return tag_.raw_dump(); +} + +std::string TSet::to_string(const Corpus2::Tagset& tagset) const +{ + return tagset.tag_to_symbol_string(tag_); +} + } /* end ns Wccl */ diff --git a/libwccl/values/tset.h b/libwccl/values/tset.h index 1618e0d..5cd25a4 100644 --- a/libwccl/values/tset.h +++ b/libwccl/values/tset.h @@ -33,6 +33,10 @@ public: return tag_; } + std::string to_string(const Corpus2::Tagset &) const; + + std::string to_raw_string() const; + private: Corpus2::Tag tag_; }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e56b4db..fa45b87 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,10 +5,11 @@ include_directories( ${CMAKE_SOURCE_DIR} ) add_definitions(-DLIBWCCL_TEST_DATA_DIR="${PROJECT_SOURCE_DIR}/") add_executable(tests + context.cpp main.cpp - variables.cpp position.cpp - context.cpp + values.cpp + variables.cpp ) target_link_libraries ( tests wccl ${Boost_LIBRARIES}) diff --git a/tests/values.cpp b/tests/values.cpp new file mode 100644 index 0000000..6d2ac2d --- /dev/null +++ b/tests/values.cpp @@ -0,0 +1,28 @@ +#include <boost/test/unit_test.hpp> +#include <boost/bind.hpp> + +#include <libwccl/variables.h> + +#include <iostream> + +using namespace Wccl; + +BOOST_AUTO_TEST_SUITE(values) + +BOOST_AUTO_TEST_CASE(boolz) +{ + Bool b; + BOOST_CHECK_EQUAL(b.get_value(), false); + Value& v = b; + BOOST_CHECK_EQUAL(v.get_type_name(), Bool::type_name); +} + +BOOST_AUTO_TEST_CASE(tsetz) +{ + TSet t; + BOOST_CHECK(t.get_tag().is_null()); + Value& v = t; + BOOST_CHECK_EQUAL(v.get_type_name(), TSet::type_name); +} + +BOOST_AUTO_TEST_SUITE_END() -- GitLab