Compare commits
1 commit
main
...
fix-window
Author | SHA1 | Date | |
---|---|---|---|
511a920f22 |
10 changed files with 72 additions and 189 deletions
|
@ -9,6 +9,8 @@ project(
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
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(src)
|
||||||
add_subdirectory(include)
|
add_subdirectory(include)
|
||||||
|
|
|
@ -60,16 +60,6 @@ if (NOT TARGET JSONCPP)
|
||||||
message(SEND_ERROR "Did not find jsoncpp")
|
message(SEND_ERROR "Did not find jsoncpp")
|
||||||
endif()
|
endif()
|
||||||
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)
|
if (NOT TARGET CRYPTO)
|
||||||
find_library(
|
find_library(
|
||||||
CRYPTO
|
CRYPTO
|
||||||
|
@ -103,12 +93,15 @@ else()
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
find_path(SYSTEM_INCLUDE_DIR curl/curl.h)
|
||||||
|
message("System include dir ${SYSTEM_INCLUDE_DIR}")
|
||||||
|
|
||||||
target_include_directories(libtwigs PUBLIC
|
target_include_directories(libtwigs PUBLIC
|
||||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${TWIGS_INCLUDE_DIR}>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${TWIGS_INCLUDE_DIR}>
|
||||||
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/twigs>
|
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/twigs>
|
||||||
SYSTEM ${CMAKE_INCLUDE_PATH}
|
SYSTEM ${CMAKE_INCLUDE_PATH}
|
||||||
SYSTEM /usr/local/include
|
SYSTEM ${SYSTEM_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(libtwigs ${JSONCPP}
|
target_link_libraries(libtwigs ${JSONCPP}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <twigs/budget.h>
|
#include <twigs/budget.h>
|
||||||
#include <twigs/utils.h>
|
#include <twigs/utils.h>
|
||||||
#include <jsoncpp/json/json.h>
|
#include <json/json.h>
|
||||||
|
|
||||||
Budget::Budget() : Budget(util::randomId(), "", "") {}
|
Budget::Budget() : Budget(util::randomId(), "", "") {}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include <jsoncpp/json/json.h>
|
#include <json/json.h>
|
||||||
#include <twigs/serializable.h>
|
#include <twigs/serializable.h>
|
||||||
#include <twigs/transaction.h>
|
#include <twigs/transaction.h>
|
||||||
#include <twigs/utils.h>
|
#include <twigs/utils.h>
|
||||||
|
|
|
@ -1,32 +1,25 @@
|
||||||
set(TWIGS_INCLUDE_DIR ../../include)
|
set(TWIGS_INCLUDE_DIR ../../include)
|
||||||
|
|
||||||
set(TEST_SOURCES
|
set(TEST_SOURCES
|
||||||
main.cpp
|
|
||||||
budget_test.h
|
|
||||||
budget_test.cpp
|
budget_test.cpp
|
||||||
transaction_test.h
|
|
||||||
transaction_test.cpp
|
transaction_test.cpp
|
||||||
utils_test.h
|
|
||||||
utils_test.cpp
|
utils_test.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
find_library(CPPUNIT cppunit)
|
enable_testing()
|
||||||
|
|
||||||
|
find_package(GTest REQUIRED)
|
||||||
|
|
||||||
|
include(GoogleTest)
|
||||||
|
|
||||||
add_executable(twigs_test ${TEST_SOURCES})
|
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
|
set_target_properties(twigs_test PROPERTIES
|
||||||
OUTPUT_NAME "twigstest"
|
OUTPUT_NAME "twigstest"
|
||||||
VERSION ${PROJECT_VERSION}
|
VERSION ${PROJECT_VERSION}
|
||||||
SOVERSION ${PROJECT_VERSION_MAJOR}
|
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||||
)
|
)
|
||||||
|
|
||||||
add_test(NAME twigs_test
|
|
||||||
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:twigs_test>
|
|
||||||
)
|
|
||||||
|
|
||||||
add_custom_command(TARGET twigs_test
|
|
||||||
POST_BUILD
|
|
||||||
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:twigs_test>
|
|
||||||
)
|
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
#ifndef BUDGET_TEST_H_INCLUDED
|
|
||||||
#define BUDGET_TEST_H_INCLUDED
|
|
||||||
|
|
||||||
#include <cppunit/TestCase.h>
|
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
|
||||||
#include <twigs/budget.h>
|
|
||||||
|
|
||||||
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
|
|
|
@ -1,20 +0,0 @@
|
||||||
#include <cppunit/TextTestRunner.h>
|
|
||||||
#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;
|
|
||||||
}
|
|
|
@ -1,84 +1,68 @@
|
||||||
#include "transaction_test.h"
|
#include <gtest/gtest.h>
|
||||||
#include <cppunit/TestCase.h>
|
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <twigs/transaction.h>
|
||||||
#include <twigs/utils.h>
|
#include <twigs/utils.h>
|
||||||
|
|
||||||
void TransactionTest::serialize() {
|
TEST(TransactionTest, SerializeTest) {
|
||||||
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;
|
const std::string json =
|
||||||
date.tm_year = 2021;
|
R"({"amount":2108,"budgetId":"Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU","categoryId":"Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4","createdBy":"1","date":"2021-01-08T13:06:00Z","description":"Books","expense":true,"id":"2snbSS8flrSH6OrvmSEmqyvaduOi2uc2","title":"Amazon"})";
|
||||||
date.tm_mon = 0;
|
|
||||||
date.tm_mday = 8;
|
tm date;
|
||||||
date.tm_hour = 13;
|
date.tm_year = 2021;
|
||||||
date.tm_min = 6;
|
date.tm_mon = 0;
|
||||||
date.tm_sec = 0;
|
date.tm_mday = 8;
|
||||||
Transaction t =
|
date.tm_hour = 13;
|
||||||
Transaction("2snbSS8flrSH6OrvmSEmqyvaduOi2uc2", "Amazon", date, "1", 2108,
|
date.tm_min = 6;
|
||||||
"Books", true, "Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4",
|
date.tm_sec = 0;
|
||||||
"Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU");
|
Transaction t = Transaction("2snbSS8flrSH6OrvmSEmqyvaduOi2uc2", "Amazon", date, "1", 2108,
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction serialization failed", json,
|
"Books", true, "Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4",
|
||||||
t.serialize());
|
"Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU");
|
||||||
|
EXPECT_EQ(t.serialize(), json) << "Transaction serialization failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionTest::deserialize() {
|
TEST(TransactionTest, DerializeTest) {
|
||||||
const std::string json =
|
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"})";
|
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);
|
Transaction t = Transaction::deserialize(json);
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction id parsing failed",
|
EXPECT_EQ(std::string("2snbSS8flrSH6OrvmSEmqyvaduOi2uc2"), t.getId()) << "Transaction id parsing failed";
|
||||||
std::string("2snbSS8flrSH6OrvmSEmqyvaduOi2uc2"),
|
EXPECT_EQ(std::string("Amazon"), t.getName()) << "Transaction name parsing failed";
|
||||||
t.getId());
|
EXPECT_EQ(std::string("Books"), t.getDescription()) << "Transaction description parsing failed";
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction name parsing failed",
|
tm date = t.getDate();
|
||||||
std::string("Amazon"), t.getName());
|
EXPECT_EQ(2021, date.tm_year) << "Transaction date year parsing failed";
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction description parsing failed",
|
EXPECT_EQ(0, date.tm_mon) << "Transaction date month parsing failed";
|
||||||
std::string("Books"), t.getDescription());
|
EXPECT_EQ(8, date.tm_mday) << "Transaction date day parsing failed";
|
||||||
tm date = t.getDate();
|
EXPECT_EQ(13, date.tm_hour) << "Transaction date hour parsing failed";
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction date year parsing failed", 2021,
|
EXPECT_EQ(6, date.tm_min) << "Transaction date min parsing failed";
|
||||||
date.tm_year);
|
EXPECT_EQ(0, date.tm_sec) << "Transaction date sec parsing failed";
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction date month parsing failed", 0,
|
EXPECT_EQ(2108U, t.getAmount()) << "Transaction amount parsing failed";
|
||||||
date.tm_mon);
|
EXPECT_TRUE(t.isExpense()) << "Transaction expense parsing failed";
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction date day parsing failed", 8,
|
EXPECT_EQ(std::string("Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU"), t.getBudgetId()) << "Transaction budgetId parsing failed";
|
||||||
date.tm_mday);
|
EXPECT_EQ(std::string("Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4"), t.getCategoryId()) << "Transaction category parsing failed";
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction date hour parsing failed", 13,
|
EXPECT_EQ(std::string("1"), t.getCreatedBy()) << "Transaction createdBy parsing failed";
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionTest::defaultIdsDifferent() {
|
TEST(TransactionTest, DefaultIdsDifferentTest) {
|
||||||
Transaction t1;
|
Transaction t1;
|
||||||
Transaction t2;
|
Transaction t2;
|
||||||
CPPUNIT_ASSERT(t1.getId() != t2.getId());
|
EXPECT_NE(t1.getId(), t2.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionTest::hashTransaction() {
|
TEST(TransactionTest, HashTransactionTest) {
|
||||||
tm date;
|
tm date;
|
||||||
date.tm_year = 2021;
|
date.tm_year = 2021;
|
||||||
date.tm_mon = 0;
|
date.tm_mon = 0;
|
||||||
date.tm_mday = 8;
|
date.tm_mday = 8;
|
||||||
date.tm_hour = 13;
|
date.tm_hour = 13;
|
||||||
date.tm_min = 6;
|
date.tm_min = 6;
|
||||||
date.tm_sec = 0;
|
date.tm_sec = 0;
|
||||||
Transaction t =
|
Transaction t =
|
||||||
Transaction("2snbSS8flrSH6OrvmSEmqyvaduOi2uc2", "Amazon", date, "1", 2108,
|
Transaction("2snbSS8flrSH6OrvmSEmqyvaduOi2uc2", "Amazon", date, "1", 2108,
|
||||||
"Books", true, "Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4",
|
"Books", true, "Q4R8QLhSksL2wi7XzmrqhL06qm2aZ2S4",
|
||||||
"Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU");
|
"Gbhqm79yC8NereIONtq7W2Mf9MD2y1AU");
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("Transaction hash failed",
|
EXPECT_EQ(std::string("94140eb2923e905360cef1e7aca3d321da39f0608ea17eb944475d81b89a64cb"), t.hash()) << "Transaction hash failed";
|
||||||
std::string("94140eb2923e905360cef1e7aca3d321da39f0608ea17eb944475d81b89a64cb"), t.hash());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int result = RUN_ALL_TESTS();
|
|
@ -1,24 +0,0 @@
|
||||||
#ifndef TRANSACTION_TEST_H_INCLUDED
|
|
||||||
#define TRANSACTION_TEST_H_INCLUDED
|
|
||||||
|
|
||||||
#include <cppunit/TestCase.h>
|
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
|
||||||
#include <twigs/transaction.h>
|
|
||||||
|
|
||||||
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
|
|
|
@ -1,21 +0,0 @@
|
||||||
#ifndef UTILS_TEST_H_INCLUDED
|
|
||||||
#define UTILS_TEST_H_INCLUDED
|
|
||||||
|
|
||||||
#include <cppunit/TestCase.h>
|
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
|
||||||
#include <twigs/utils.h>
|
|
||||||
|
|
||||||
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
|
|
Loading…
Reference in a new issue