Compare commits

...

1 commit

Author SHA1 Message Date
511a920f22 WIP:Fix builds on Windows 2021-05-18 20:53:40 -06:00
10 changed files with 72 additions and 189 deletions

View file

@ -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)

View file

@ -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
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${TWIGS_INCLUDE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/twigs>
SYSTEM ${CMAKE_INCLUDE_PATH}
SYSTEM /usr/local/include
SYSTEM ${SYSTEM_INCLUDE_DIR}
)
target_link_libraries(libtwigs ${JSONCPP}

View file

@ -1,7 +1,7 @@
#include <string>
#include <twigs/budget.h>
#include <twigs/utils.h>
#include <jsoncpp/json/json.h>
#include <json/json.h>
Budget::Budget() : Budget(util::randomId(), "", "") {}

View file

@ -1,4 +1,4 @@
#include <jsoncpp/json/json.h>
#include <json/json.h>
#include <twigs/serializable.h>
#include <twigs/transaction.h>
#include <twigs/utils.h>

View file

@ -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} $<TARGET_FILE:twigs_test>
)
add_custom_command(TARGET twigs_test
POST_BUILD
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:twigs_test>
)

View file

@ -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

View file

@ -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;
}

View file

@ -1,84 +1,68 @@
#include "transaction_test.h"
#include <cppunit/TestCase.h>
#include <gtest/gtest.h>
#include <cppunit/extensions/HelperMacros.h>
#include <iostream>
#include <time.h>
#include <twigs/transaction.h>
#include <twigs/utils.h>
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();

View file

@ -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

View file

@ -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