Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Commit

Permalink
refactor gtests and add make test
Browse files Browse the repository at this point in the history
  • Loading branch information
nayuta-gondo committed Aug 17, 2018
1 parent e0e717d commit df84537
Show file tree
Hide file tree
Showing 36 changed files with 53 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,6 +12,7 @@ routing/routing

.Depend
*.o
*.a
*.log
GPATH
GRTAGS
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -34,3 +34,5 @@ addons:

script:
- make full
- make test

5 changes: 5 additions & 0 deletions Makefile
Expand Up @@ -42,3 +42,8 @@ lib_clean:

git_subs:
git submodule update --init --recursive

test:
$(MAKE) -C gtest
$(MAKE) -C ptarm test

File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion ptarm/gtests/gtest/gtest-main.cc → gtest/gtest-main.cc
@@ -1,4 +1,4 @@
#include "gtest.h"
#include "gtest/gtest.h"

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions ptarm/Makefile
Expand Up @@ -213,6 +213,11 @@ cppcheck:

clean:
$(RM) $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME) .Depend
$(MAKE) -C tests clean

test:
$(MAKE) -C tests
$(MAKE) -C tests exec

################################

Expand Down
2 changes: 2 additions & 0 deletions ptarm/ptarm.h
Expand Up @@ -1424,6 +1424,8 @@ void ptarm_print_extendedkey(const ptarm_ekey_t *pEKey);
* @return malloc残数
*/
int ptarm_dbg_malloc_cnt(void);

void ptarm_dbg_malloc_cnt_reset(void);
#endif //PTARM_DEBUG_MEM

#ifdef __cplusplus
Expand Down
4 changes: 4 additions & 0 deletions ptarm/ptarm_util.c
Expand Up @@ -399,6 +399,10 @@ int ptarm_dbg_malloc_cnt(void)
return mcount;
}

void ptarm_dbg_malloc_cnt_reset(void)
{
mcount = 0;
}
#endif //PTARM_DEBUG_MEM


Expand Down
14 changes: 8 additions & 6 deletions ptarm/gtests/Makefile → ptarm/tests/Makefile
@@ -1,4 +1,4 @@
GTEST_DIR = ./gtest
GTEST_DIR = ../../gtest
OBJECT_DIRECTORY = _ggtest

CXX=g++
Expand All @@ -15,7 +15,7 @@ TEST_TARGET_SRC += test_ptarm.cpp
# Flags passed to the preprocessor.
# Set Google Test's header directory as a system directory, such that
# the compiler doesn't generate warnings in Google Test headers.
CPPFLAGS += -isystem -I$(GTEST_DIR) -DUNITTEST -D_GLIBCXX_USE_CXX11_ABI=1
CPPFLAGS += -isystem $(GTEST_DIR)/.. -DUNITTEST -D_GLIBCXX_USE_CXX11_ABI=1
CPPFLAGS += -DNDEBUG
CPPFLAGS += -DPTARM_DEBUG
CPPFLAGS += -DPTARM_DEBUG_MEM
Expand Down Expand Up @@ -44,7 +44,7 @@ vpath %.cpp $(TEST_PATHS)

all: .Depend unittest

unittest : $(OBJECT_DIRECTORY) $(GTEST_DIR)/gtest_main.a $(TEST_OBJECTS)
unittest: $(OBJECT_DIRECTORY) $(GTEST_DIR)/gtest_main.a $(TEST_OBJECTS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(TEST_OBJECTS) $(GTEST_DIR)/gtest_main.a -o $(OBJECT_DIRECTORY)/$@ $(LDFLAGS)

$(OBJECT_DIRECTORY):
Expand All @@ -62,15 +62,17 @@ $(GTEST_DIR)/gtest_main.a:
make -C $(GTEST_DIR)

.Depend:
ifneq ($(MAKECMDGOALS),clean)
$(foreach SRC,$(TEST_TARGET_SRC),$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MM -MT $(OBJECT_DIRECTORY)/$(SRC:.cpp=.o) $(SRC) >> .Depend;)
endif

rmlcov :
rmlcov:
$(RM) $(OBJECT_DIRECTORY)/*.gcda

clean :
clean:
@$(RM) $(OBJECT_DIRECTORY) .Depend

clobber : clean
clobber: clean
make -C $(GTEST_DIR) clean

exec: rmlcov
Expand Down
Expand Up @@ -9,6 +9,7 @@ class xxx: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, false);
}

Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions ptarm/gtests/test_ptarm.cpp → ptarm/tests/test_ptarm.cpp
Expand Up @@ -50,6 +50,7 @@ TEST_F(ptarm, first)

TEST_F(ptarm, ptarm_setnet_testnet_false)
{
ptarm_dbg_malloc_cnt_reset();
bool ret = ptarm_init(PTARM_TESTNET, false);
ASSERT_TRUE(ret);
ASSERT_EQ(2, mPref[PTARM_PREF]);
Expand All @@ -63,6 +64,7 @@ TEST_F(ptarm, ptarm_setnet_testnet_false)

TEST_F(ptarm, ptarm_setnet_testnet_true)
{
ptarm_dbg_malloc_cnt_reset();
bool ret = ptarm_init(PTARM_TESTNET, true);
ASSERT_TRUE(ret);
ASSERT_EQ(2, mPref[PTARM_PREF]);
Expand All @@ -76,6 +78,7 @@ TEST_F(ptarm, ptarm_setnet_testnet_true)

TEST_F(ptarm, ptarm_setnet_mainnet)
{
ptarm_dbg_malloc_cnt_reset();
bool ret = ptarm_init(PTARM_MAINNET, false);
ASSERT_TRUE(ret);
ASSERT_EQ(1, mPref[PTARM_PREF]);
Expand Down
Expand Up @@ -9,6 +9,7 @@ class bech32: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, false);
}

Expand Down
Expand Up @@ -9,6 +9,7 @@ class buf: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, false);
}

Expand Down
Expand Up @@ -9,6 +9,7 @@ class extendedkey: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_MAINNET, false);
}

Expand Down Expand Up @@ -501,6 +502,7 @@ TEST_F(extendedkey, chain_m_master2)

TEST_F(extendedkey, chain_testnet)
{
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, false);

uint8_t buf_ekey[PTARM_SZ_EKEY];
Expand Down
File renamed without changes.
Expand Up @@ -9,6 +9,7 @@ class keys: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, false);
}

Expand Down
Expand Up @@ -9,6 +9,7 @@ class keys_native: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, true);
}

Expand Down
1 change: 1 addition & 0 deletions ptarm/gtests/testinc_ln.cpp → ptarm/tests/testinc_ln.cpp
Expand Up @@ -9,6 +9,7 @@ class ln: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, true);
}

Expand Down
Expand Up @@ -42,6 +42,7 @@ ptarm_util_keys_t ln_bolt3_b::keys;

TEST_F(ln_bolt3_b, fuding1)
{
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, true);


Expand Down
Expand Up @@ -264,6 +264,7 @@ ln_htlcinfo_t** ln_bolt3_c::pp_htlcinfos;

TEST_F(ln_bolt3_c, start)
{
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, true);
}

Expand Down
Expand Up @@ -14,6 +14,7 @@ class ln_bolt3_d: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, true);
}

Expand Down
Expand Up @@ -9,6 +9,7 @@ class ln_derkey: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, true);
}

Expand Down
Expand Up @@ -17,6 +17,7 @@ class onion: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, true);
ptarm_buf_init(&sOnionBuffer);
spEphPubkey = NULL;
Expand Down
Expand Up @@ -9,6 +9,7 @@ class bolt8test: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, true);
}

Expand Down
Expand Up @@ -9,6 +9,7 @@ class misc: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, false);
}

Expand Down
Expand Up @@ -9,6 +9,7 @@ class push: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, false);
}

Expand Down
Expand Up @@ -9,6 +9,7 @@ class recoverpub: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, false);
}

Expand Down
Expand Up @@ -9,6 +9,7 @@ class sw: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, false);
}

Expand Down
Expand Up @@ -9,6 +9,7 @@ class send: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, false);
}

Expand Down
Expand Up @@ -9,6 +9,7 @@ class sw_native: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, true);
}

Expand Down
1 change: 1 addition & 0 deletions ptarm/gtests/testinc_tx.cpp → ptarm/tests/testinc_tx.cpp
Expand Up @@ -9,6 +9,7 @@ class tx: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, false);
}

Expand Down
Expand Up @@ -9,6 +9,7 @@ class tx_native: public testing::Test {
protected:
virtual void SetUp() {
//RESET_FAKE(external_function)
ptarm_dbg_malloc_cnt_reset();
ptarm_init(PTARM_TESTNET, true);
}

Expand Down

0 comments on commit df84537

Please sign in to comment.