diff --git a/CMakeLists.txt b/CMakeLists.txt index 52e7524..3f5ed3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ project( set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}") +set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}") add_subdirectory(src) add_subdirectory(include) diff --git a/src/libtwigs/CMakeLists.txt b/src/libtwigs/CMakeLists.txt index a66f1ec..6585973 100644 --- a/src/libtwigs/CMakeLists.txt +++ b/src/libtwigs/CMakeLists.txt @@ -60,16 +60,6 @@ if (NOT TARGET JSONCPP) message(SEND_ERROR "Did not find jsoncpp") endif() endif() -#if (NOT TARGET JSONC) - #find_library( - #JSONC - #NAMES json-c libjson-c - #PATHS /usr/local/lib /usr/local/lib64 /usr/lib /usr/lib64 /lib - #) - #if (NOT JSONC) - #message(SEND_ERROR "Did not find json-c") - #endif() -#endif() if (NOT TARGET CRYPTO) find_library( CRYPTO @@ -103,12 +93,15 @@ else() ) endif() +find_path(SYSTEM_INCLUDE_DIR curl/curl.h) +message("System include dir ${SYSTEM_INCLUDE_DIR}") + target_include_directories(libtwigs PUBLIC $ $ $ SYSTEM ${CMAKE_INCLUDE_PATH} - SYSTEM /usr/local/include + SYSTEM ${SYSTEM_INCLUDE_DIR} ) target_link_libraries(libtwigs ${JSONCPP} diff --git a/src/libtwigs/budget.cpp b/src/libtwigs/budget.cpp index ca28fe4..e1568fe 100644 --- a/src/libtwigs/budget.cpp +++ b/src/libtwigs/budget.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include Budget::Budget() : Budget(util::randomId(), "", "") {} diff --git a/src/libtwigs/transaction.cpp b/src/libtwigs/transaction.cpp index 24e3b0c..70d1534 100644 --- a/src/libtwigs/transaction.cpp +++ b/src/libtwigs/transaction.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 8d0620d..79ced70 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1,32 +1,25 @@ set(TWIGS_INCLUDE_DIR ../../include) set(TEST_SOURCES - main.cpp - budget_test.h budget_test.cpp - transaction_test.h transaction_test.cpp - utils_test.h utils_test.cpp ) -find_library(CPPUNIT cppunit) +enable_testing() + +find_package(GTest REQUIRED) + +include(GoogleTest) add_executable(twigs_test ${TEST_SOURCES}) -target_link_libraries(twigs_test libtwigs ${CPPUNIT}) - +target_link_libraries(twigs_test libtwigs GTest::GTest GTest::Main) + +gtest_discover_tests(twigs_test) + set_target_properties(twigs_test PROPERTIES OUTPUT_NAME "twigstest" VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} ) - -add_test(NAME twigs_test - COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $ -) - -add_custom_command(TARGET twigs_test - POST_BUILD - COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $ - ) diff --git a/src/test/budget_test.h b/src/test/budget_test.h deleted file mode 100644 index 62e14de..0000000 --- a/src/test/budget_test.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef BUDGET_TEST_H_INCLUDED -#define BUDGET_TEST_H_INCLUDED - -#include -#include -#include - -class BudgetTest: public CppUnit::TestCase { -public: - void serialize(); - void deserialize(); - void defaultIdsDifferent(); - void hashBudget(); - - CPPUNIT_TEST_SUITE( BudgetTest ); - CPPUNIT_TEST( serialize ); - CPPUNIT_TEST( deserialize ); - CPPUNIT_TEST( defaultIdsDifferent ); - CPPUNIT_TEST( hashBudget ); - CPPUNIT_TEST_SUITE_END(); -}; - - -#endif // BUDGET_TEST_H_INCLUDED diff --git a/src/test/main.cpp b/src/test/main.cpp deleted file mode 100644 index 1a0d2fe..0000000 --- a/src/test/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include "budget_test.h" -#include "transaction_test.h" -#include "utils_test.h" - -CPPUNIT_TEST_SUITE_REGISTRATION (UtilsTest); -CPPUNIT_TEST_SUITE_REGISTRATION (BudgetTest); -CPPUNIT_TEST_SUITE_REGISTRATION (TransactionTest); - -int main() { - BudgetTest budgetTest; - TransactionTest transactionTest; - UtilsTest utilsTest; - - CppUnit::Test *test = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); - CppUnit::TextTestRunner runner; - runner.addTest(test); - runner.run(); - return 0; -} diff --git a/src/test/transaction_test.cpp b/src/test/transaction_test.cpp index 0625834..25ce459 100644 --- a/src/test/transaction_test.cpp +++ b/src/test/transaction_test.cpp @@ -1,84 +1,68 @@ -#include "transaction_test.h" -#include +#include #include #include #include +#include #include -void TransactionTest::serialize() { - const std::string json = - R"({"amount":2108,"budgetId":"Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU","categoryId":"Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4","createdBy":"1","date":"2021-01-08T13:06:00Z","description":"Books","expense":true,"id":"2snbSS8flrSH6OrvmSEmqyvaduOi2uc2","title":"Amazon"})"; +TEST(TransactionTest, SerializeTest) { - tm date; - date.tm_year = 2021; - date.tm_mon = 0; - date.tm_mday = 8; - date.tm_hour = 13; - date.tm_min = 6; - date.tm_sec = 0; - Transaction t = - Transaction("2snbSS8flrSH6OrvmSEmqyvaduOi2uc2", "Amazon", date, "1", 2108, - "Books", true, "Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4", - "Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU"); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction serialization failed", json, - t.serialize()); + const std::string json = + R"({"amount":2108,"budgetId":"Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU","categoryId":"Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4","createdBy":"1","date":"2021-01-08T13:06:00Z","description":"Books","expense":true,"id":"2snbSS8flrSH6OrvmSEmqyvaduOi2uc2","title":"Amazon"})"; + + tm date; + date.tm_year = 2021; + date.tm_mon = 0; + date.tm_mday = 8; + date.tm_hour = 13; + date.tm_min = 6; + date.tm_sec = 0; + Transaction t = Transaction("2snbSS8flrSH6OrvmSEmqyvaduOi2uc2", "Amazon", date, "1", 2108, + "Books", true, "Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4", + "Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU"); + EXPECT_EQ(t.serialize(), json) << "Transaction serialization failed"; } -void TransactionTest::deserialize() { - const std::string json = - R"({"id":"2snbSS8flrSH6OrvmSEmqyvaduOi2uc2","title":"Amazon","description":"Books","date":"2021-01-08T13:06:00Z","amount":2108,"expense":true,"budgetId":"Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU","categoryId":"Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4","createdBy":"1"})"; - Transaction t = Transaction::deserialize(json); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction id parsing failed", - std::string("2snbSS8flrSH6OrvmSEmqyvaduOi2uc2"), - t.getId()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction name parsing failed", - std::string("Amazon"), t.getName()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction description parsing failed", - std::string("Books"), t.getDescription()); - tm date = t.getDate(); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction date year parsing failed", 2021, - date.tm_year); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction date month parsing failed", 0, - date.tm_mon); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction date day parsing failed", 8, - date.tm_mday); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction date hour parsing failed", 13, - date.tm_hour); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction date min parsing failed", 6, - date.tm_min); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction date sec parsing failed", 0, - date.tm_sec); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction amount parsing failed", 2108U, - t.getAmount()); - CPPUNIT_ASSERT_MESSAGE("Transaction expense parsing failed", t.isExpense()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction budgetId parsing failed", - std::string("Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU"), - t.getBudgetId()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction category parsing failed", - std::string("Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4"), - t.getCategoryId()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction createdBy parsing failed", - std::string("1"), t.getCreatedBy()); +TEST(TransactionTest, DerializeTest) { + const std::string json = + R"({"id":"2snbSS8flrSH6OrvmSEmqyvaduOi2uc2","title":"Amazon","description":"Books","date":"2021-01-08T13:06:00Z","amount":2108,"expense":true,"budgetId":"Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU","categoryId":"Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4","createdBy":"1"})"; + Transaction t = Transaction::deserialize(json); + EXPECT_EQ(std::string("2snbSS8flrSH6OrvmSEmqyvaduOi2uc2"), t.getId()) << "Transaction id parsing failed"; + EXPECT_EQ(std::string("Amazon"), t.getName()) << "Transaction name parsing failed"; + EXPECT_EQ(std::string("Books"), t.getDescription()) << "Transaction description parsing failed"; + tm date = t.getDate(); + EXPECT_EQ(2021, date.tm_year) << "Transaction date year parsing failed"; + EXPECT_EQ(0, date.tm_mon) << "Transaction date month parsing failed"; + EXPECT_EQ(8, date.tm_mday) << "Transaction date day parsing failed"; + EXPECT_EQ(13, date.tm_hour) << "Transaction date hour parsing failed"; + EXPECT_EQ(6, date.tm_min) << "Transaction date min parsing failed"; + EXPECT_EQ(0, date.tm_sec) << "Transaction date sec parsing failed"; + EXPECT_EQ(2108U, t.getAmount()) << "Transaction amount parsing failed"; + EXPECT_TRUE(t.isExpense()) << "Transaction expense parsing failed"; + EXPECT_EQ(std::string("Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU"), t.getBudgetId()) << "Transaction budgetId parsing failed"; + EXPECT_EQ(std::string("Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4"), t.getCategoryId()) << "Transaction category parsing failed"; + EXPECT_EQ(std::string("1"), t.getCreatedBy()) << "Transaction createdBy parsing failed"; } -void TransactionTest::defaultIdsDifferent() { - Transaction t1; - Transaction t2; - CPPUNIT_ASSERT(t1.getId() != t2.getId()); +TEST(TransactionTest, DefaultIdsDifferentTest) { + Transaction t1; + Transaction t2; + EXPECT_NE(t1.getId(), t2.getId()); } -void TransactionTest::hashTransaction() { - tm date; - date.tm_year = 2021; - date.tm_mon = 0; - date.tm_mday = 8; - date.tm_hour = 13; - date.tm_min = 6; - date.tm_sec = 0; - Transaction t = - Transaction("2snbSS8flrSH6OrvmSEmqyvaduOi2uc2", "Amazon", date, "1", 2108, - "Books", true, "Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4", - "Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU"); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction hash failed", - std::string("94140eb2923e905360cef1e7aca3d321da39f0608ea17eb944475d81b89a64cb"), t.hash()); +TEST(TransactionTest, HashTransactionTest) { + tm date; + date.tm_year = 2021; + date.tm_mon = 0; + date.tm_mday = 8; + date.tm_hour = 13; + date.tm_min = 6; + date.tm_sec = 0; + Transaction t = + Transaction("2snbSS8flrSH6OrvmSEmqyvaduOi2uc2", "Amazon", date, "1", 2108, + "Books", true, "Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4", + "Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU"); + EXPECT_EQ(std::string("94140eb2923e905360cef1e7aca3d321da39f0608ea17eb944475d81b89a64cb"), t.hash()) << "Transaction hash failed"; } + +int result = RUN_ALL_TESTS(); \ No newline at end of file diff --git a/src/test/transaction_test.h b/src/test/transaction_test.h deleted file mode 100644 index 5c6e35b..0000000 --- a/src/test/transaction_test.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef TRANSACTION_TEST_H_INCLUDED -#define TRANSACTION_TEST_H_INCLUDED - -#include -#include -#include - -class TransactionTest: public CppUnit::TestCase { -public: - void serialize(); - void deserialize(); - void defaultIdsDifferent(); - void hashTransaction(); - - CPPUNIT_TEST_SUITE( TransactionTest ); - CPPUNIT_TEST( serialize ); - CPPUNIT_TEST( deserialize ); - CPPUNIT_TEST( defaultIdsDifferent ); - CPPUNIT_TEST( hashTransaction ); - CPPUNIT_TEST_SUITE_END(); -}; - - -#endif // TRANSACTION_TEST_H_INCLUDED diff --git a/src/test/utils_test.h b/src/test/utils_test.h deleted file mode 100644 index 1962048..0000000 --- a/src/test/utils_test.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef UTILS_TEST_H_INCLUDED -#define UTILS_TEST_H_INCLUDED - -#include -#include -#include - -class UtilsTest: public CppUnit::TestCase { -public: - void parseDateTest(); - void printDateTest(); - void hashTest(); - - CPPUNIT_TEST_SUITE( UtilsTest ); - CPPUNIT_TEST( parseDateTest ); - CPPUNIT_TEST( printDateTest ); - CPPUNIT_TEST( hashTest ); - CPPUNIT_TEST_SUITE_END(); -}; - -#endif // UTILS_TEST_H_INCLUDED