forked from BOINC/boinc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'gtest' of https://github.com/Uplinger/boinc into Upling…
…er-gtest
- Loading branch information
Showing
7 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Location of GTEST | ||
GTEST_DIR = ../../googletest/googletest | ||
GTEST_MAIN = ${GTEST_DIR}/make/gtest_main.a | ||
|
||
# BOINC Libraries | ||
BOINC_DIR = .. | ||
BOINC_LIB = ${BOINC_DIR}/sched/libsched.a ${BOINC_DIR}/lib/libboinc_crypt.a ${BOINC_DIR}/lib/libboinc.a -lpthread -L/usr/lib64/mysql -lmysqlclient -ldl -lz -L/usr/lib64 -lssl -lcrypto | ||
BOINC_INC = -I ${BOINC_DIR}/sched -I ${BOINC_DIR}/db -I ${BOINC_DIR}/lib -I ${BOINC_DIR}/tools -I ${BOINC_DIR}/vda -I ${BOINC_DIR} | ||
|
||
# Additional Libraries | ||
OTHER_INC = -I /usr/include/mysql | ||
|
||
# Flags passed to the preprocessor. | ||
CPPFLAGS = -isystem $(GTEST_DIR)/include ${BOINC_INC} ${OTHER_INC} | ||
|
||
# Flags passed to the C++ compiler. | ||
CXXFLAGS = -g -Wall -Wextra -Werror | ||
|
||
# Include all source files | ||
#cppsrc = $(wildcard *.cpp) \ | ||
# $(wildcard sched/*.cpp) \ | ||
# $(wildcard lib/*.cpp) | ||
|
||
#obj = $(cppsrc:.cpp=.o) | ||
obj = $(wildcard *.o) \ | ||
$(wildcard sched/*.o) \ | ||
$(wildcard lib/*.o) | ||
|
||
all: Sched Lib unitTests | ||
|
||
Sched: | ||
cd sched ; make -f Makefile.gtest | ||
|
||
Lib: | ||
cd lib ; make -f Makefile.gtest | ||
|
||
unitTests: Sched Lib | ||
g++ $(CPPFLAGS) $(CXXFLAGS) $(wildcard sched/*.o) $(wildcard lib/*.o) -o $@ ${GTEST_MAIN} ${BOINC_LIB} | ||
|
||
clean: | ||
rm -f *.o ${obj} unitTests | ||
|
||
test: | ||
./unitTests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
This is the start gtest example for unit tests. To run, you should only need to run these commands. | ||
|
||
Setup: | ||
You will need to have googletest downloaded and compiled on your local machine first. The Makefile expects it to be in the same directory level as boinc. (example: /home/user/boinc and /home/user/googletest) | ||
|
||
git clone https://github.com/google/googletest.git | ||
cd googletest | ||
git pull | ||
cd googletest/make | ||
make | ||
|
||
The next commands are done within the boinc/gtest folder. | ||
|
||
To compile the code. | ||
make -f Makefile.gtest | ||
|
||
To run the tests. | ||
make -f Makefile.gtest test | ||
|
||
To cleanup the old files. | ||
make -f Makefile.gtest clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Location of GTEST | ||
GTEST_DIR = ../../../googletest/googletest | ||
GTEST_MAIN = ${GTEST_DIR}/make/gtest_main.a | ||
|
||
# BOINC Libraries | ||
BOINC_DIR = ../.. | ||
BOINC_LIB = ${BOINC_DIR}/sched/libsched.a ${BOINC_DIR}/lib/libboinc_crypt.a ${BOINC_DIR}/lib/libboinc.a ${BOINC_DIR}/sched/sched_types.o ${BOINC_DIR}/sched/handle_request.o -lpthread -L/usr/lib64/mysql -lmysqlclient -ldl -lz -L/usr/lib64 -lssl -lcrypto | ||
BOINC_INC = -I ${BOINC_DIR}/sched -I ${BOINC_DIR}/db -I ${BOINC_DIR}/lib -I ${BOINC_DIR}/tools -I ${BOINC_DIR}/vda -I ${BOINC_DIR} | ||
|
||
# Additional Libraries | ||
OTHER_INC = -I /usr/include/mysql | ||
|
||
# Flags passed to the preprocessor. | ||
CPPFLAGS = -isystem $(GTEST_DIR)/include ${BOINC_INC} ${OTHER_INC} | ||
|
||
# Flags passed to the C++ compiler. | ||
CXXFLAGS = -g -Wall -Wextra -Werror | ||
|
||
# Include all source files | ||
cppsrc = $(wildcard *.cpp) | ||
|
||
obj = $(cppsrc:.cpp=.o) | ||
|
||
all: ${obj} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "gtest/gtest.h" | ||
#include "common_defs.h" | ||
#include "str_util.h" | ||
#include <string> | ||
#include <ios> | ||
|
||
namespace test_str_util { | ||
|
||
// The fixture for testing class Foo. | ||
|
||
class test_str_util : public ::testing::Test { | ||
protected: | ||
// You can remove any or all of the following functions if its body | ||
// is empty. | ||
|
||
test_str_util() { | ||
// You can do set-up work for each test here. | ||
} | ||
|
||
virtual ~test_str_util() { | ||
// You can do clean-up work that doesn't throw exceptions here. | ||
} | ||
|
||
// If the constructor and destructor are not enough for setting up | ||
// and cleaning up each test, you can define the following methods: | ||
|
||
virtual void SetUp() { | ||
// Code here will be called immediately after the constructor (right | ||
// before each test). | ||
} | ||
|
||
virtual void TearDown() { | ||
// Code here will be called immediately after each test (right | ||
// before the destructor). | ||
} | ||
|
||
// Objects declared here can be used by all tests in the test case for Foo. | ||
}; | ||
|
||
// Tests that Foo does Xyz. | ||
|
||
TEST_F(test_str_util, path_to_filename) { | ||
std::string fname = ""; | ||
ASSERT_EQ(path_to_filename("/home/blah", fname), 0); | ||
ASSERT_EQ(fname, "blah"); | ||
ASSERT_EQ(path_to_filename("hellokeith", fname), 0); | ||
ASSERT_EQ(fname, "hellokeith"); | ||
fname = ""; | ||
ASSERT_EQ(path_to_filename("/home/blah/", fname), -2); | ||
ASSERT_EQ(fname, ""); | ||
ASSERT_EQ(path_to_filename("", fname), -1); | ||
ASSERT_EQ(fname, ""); | ||
} | ||
|
||
TEST_F(test_str_util, nbytes_to_string) { | ||
char buf[256]; | ||
nbytes_to_string(1024, 0, buf, sizeof (buf)); | ||
ASSERT_STREQ(buf, "1.00 KB"); | ||
nbytes_to_string(1024, 1024 * 1024, buf, sizeof (buf)); | ||
ASSERT_STREQ(buf, "0.00/1.00 MB"); | ||
nbytes_to_string(512, 1024, buf, sizeof (buf)); | ||
ASSERT_STREQ(buf, "0.50/1.00 KB"); | ||
nbytes_to_string(50000000000000, 0, buf, sizeof (buf)); | ||
ASSERT_STREQ(buf, "45.47 TB"); | ||
} | ||
|
||
TEST_F(test_str_util, strip_whitespace) { | ||
std::string tmp = " white space "; | ||
strip_whitespace(tmp); | ||
ASSERT_EQ(tmp, "white space"); | ||
tmp = "nospaces"; | ||
strip_whitespace(tmp); | ||
ASSERT_EQ(tmp, "nospaces"); | ||
} | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "gtest/gtest.h" | ||
#include "common_defs.h" | ||
#include "url.h" | ||
#include <string> | ||
#include <ios> | ||
|
||
namespace test_url { | ||
|
||
// The fixture for testing class Foo. | ||
|
||
class test_url : public ::testing::Test { | ||
protected: | ||
// You can remove any or all of the following functions if its body | ||
// is empty. | ||
|
||
test_url() { | ||
// You can do set-up work for each test here. | ||
} | ||
|
||
virtual ~test_url() { | ||
// You can do clean-up work that doesn't throw exceptions here. | ||
} | ||
|
||
// If the constructor and destructor are not enough for setting up | ||
// and cleaning up each test, you can define the following methods: | ||
|
||
virtual void SetUp() { | ||
// Code here will be called immediately after the constructor (right | ||
// before each test). | ||
} | ||
|
||
virtual void TearDown() { | ||
// Code here will be called immediately after each test (right | ||
// before the destructor). | ||
} | ||
|
||
// Objects declared here can be used by all tests in the test case for Foo. | ||
}; | ||
|
||
// Tests that Foo does Xyz. | ||
|
||
TEST_F(test_url, is_https) { | ||
ASSERT_EQ(is_https("hello"), false); | ||
ASSERT_EQ(is_https("https://www.google.com"), true); | ||
ASSERT_EQ(is_https("http://www.google.com"), false); | ||
ASSERT_EQ(is_https("xhttps://www.google.com"), false); | ||
} | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Location of GTEST | ||
GTEST_DIR = ../../../googletest/googletest | ||
GTEST_MAIN = ${GTEST_DIR}/make/gtest_main.a | ||
|
||
# BOINC Libraries | ||
BOINC_DIR = ../.. | ||
BOINC_LIB = ${BOINC_DIR}/sched/libsched.a ${BOINC_DIR}/lib/libboinc_crypt.a ${BOINC_DIR}/lib/libboinc.a ${BOINC_DIR}/sched/sched_types.o ${BOINC_DIR}/sched/handle_request.o -lpthread -L/usr/lib64/mysql -lmysqlclient -ldl -lz -L/usr/lib64 -lssl -lcrypto | ||
BOINC_INC = -I ${BOINC_DIR}/sched -I ${BOINC_DIR}/db -I ${BOINC_DIR}/lib -I ${BOINC_DIR}/tools -I ${BOINC_DIR}/vda -I ${BOINC_DIR} | ||
|
||
# Additional Libraries | ||
OTHER_INC = -I /usr/include/mysql | ||
|
||
# Flags passed to the preprocessor. | ||
CPPFLAGS = -isystem $(GTEST_DIR)/include ${BOINC_INC} ${OTHER_INC} | ||
|
||
# Flags passed to the C++ compiler. | ||
CXXFLAGS = -g -Wall -Wextra -Werror | ||
|
||
# Include all source files | ||
cppsrc = $(wildcard *.cpp) | ||
|
||
obj = $(cppsrc:.cpp=.o) | ||
#obj = $(wildcard *.o) \ | ||
# $(wildcard sched/*.o) | ||
|
||
all: ${obj} | ||
|
||
#unitTests: ${obj} | ||
# g++ $(CPPFLAGS) $(CXXFLAGS) $^ -o $@ ${GTEST_MAIN} ${BOINC_LIB} | ||
|
||
#clean: | ||
# rm -f *.o ${obj} unitTests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "gtest/gtest.h" | ||
#include "common_defs.h" | ||
#include "credit.h" | ||
|
||
namespace test_credit { | ||
|
||
// The fixture for testing class Foo. | ||
|
||
class test_credit : public ::testing::Test { | ||
protected: | ||
// You can remove any or all of the following functions if its body | ||
// is empty. | ||
|
||
test_credit() { | ||
// You can do set-up work for each test here. | ||
} | ||
|
||
virtual ~test_credit() { | ||
// You can do clean-up work that doesn't throw exceptions here. | ||
} | ||
|
||
// If the constructor and destructor are not enough for setting up | ||
// and cleaning up each test, you can define the following methods: | ||
|
||
virtual void SetUp() { | ||
// Code here will be called immediately after the constructor (right | ||
// before each test). | ||
} | ||
|
||
virtual void TearDown() { | ||
// Code here will be called immediately after each test (right | ||
// before the destructor). | ||
} | ||
|
||
// Objects declared here can be used by all tests in the test case for Foo. | ||
}; | ||
|
||
// Tests that Foo does Xyz. | ||
|
||
TEST_F(test_credit, fpops_to_credit) { | ||
ASSERT_EQ(fpops_to_credit(1.0), COBBLESTONE_SCALE); | ||
ASSERT_NE(fpops_to_credit(5.0), COBBLESTONE_SCALE); | ||
ASSERT_EQ(fpops_to_credit(6000000.0), 6000000.0 * COBBLESTONE_SCALE); | ||
} | ||
|
||
TEST_F(test_credit, cpu_time_to_credit) { | ||
ASSERT_EQ(cpu_time_to_credit(1.0, 1.0), COBBLESTONE_SCALE); | ||
} | ||
|
||
} // namespace |