Add support for unit tests.

This commit is contained in:
Arthur Britto
2012-05-07 19:14:07 -07:00
parent c6f6914dab
commit def2e74cf3
4 changed files with 51 additions and 11 deletions

View File

@@ -46,7 +46,7 @@ DEBUGFLAGS = ['-g', '-DDEBUG']
env.Append(LINKFLAGS = ['-rdynamic', '-pthread']) env.Append(LINKFLAGS = ['-rdynamic', '-pthread'])
env.Append(CCFLAGS = ['-pthread', '-Wall', '-Wno-sign-compare', '-Wno-char-subscripts', '-DSQLITE_THREADSAFE']) env.Append(CCFLAGS = ['-pthread', '-Wall', '-Wno-sign-compare', '-Wno-char-subscripts', '-DSQLITE_THREADSAFE'])
env.Append(CXXFLAGS = ['-O0', '-pthread', '-Wno-invalid-offsetof', '-Wformat']+DEBUGFLAGS) env.Append(CXXFLAGS = ['-O0', '-pthread', '-Wno-invalid-offsetof', '-Wformat', '-DBOOST_TEST_DYN_LINK ']+DEBUGFLAGS)
DB_SRCS = glob.glob('database/*.c') + glob.glob('database/*.cpp') DB_SRCS = glob.glob('database/*.c') + glob.glob('database/*.cpp')
JSON_SRCS = glob.glob('json/*.cpp') JSON_SRCS = glob.glob('json/*.cpp')

View File

@@ -11,6 +11,7 @@
#include <iostream> #include <iostream>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/functional/hash.hpp> #include <boost/functional/hash.hpp>
#include <boost/test/unit_test.hpp>
NewcoinAddress::NewcoinAddress() NewcoinAddress::NewcoinAddress()
{ {
@@ -506,4 +507,13 @@ void NewcoinAddress::setFamilySeedRandom()
NewcoinAddress::setFamilySeed(key); NewcoinAddress::setFamilySeed(key);
} }
BOOST_AUTO_TEST_SUITE(newcoin_address)
BOOST_AUTO_TEST_CASE( my_test )
{
BOOST_CHECK( false );
}
BOOST_AUTO_TEST_SUITE_END()
// vim:ts=4 // vim:ts=4

View File

@@ -11,14 +11,14 @@ class NewcoinAddress : public CBase58Data
{ {
private: private:
typedef enum { typedef enum {
VER_NONE = 1, VER_NONE = 1,
VER_NODE_PUBLIC = 28, VER_NODE_PUBLIC = 28,
VER_NODE_PRIVATE = 32, VER_NODE_PRIVATE = 32,
VER_ACCOUNT_ID = 0, VER_ACCOUNT_ID = 0,
VER_ACCOUNT_PUBLIC = 35, VER_ACCOUNT_PUBLIC = 35,
VER_ACCOUNT_PRIVATE = 34, VER_ACCOUNT_PRIVATE = 34,
VER_FAMILY_GENERATOR = 41, VER_FAMILY_GENERATOR = 41,
VER_FAMILY_SEED = 33, VER_FAMILY_SEED = 33,
} VersionEncoding; } VersionEncoding;
void seedInfo(NewcoinAddress* dstGenerator, BIGNUM** dstPrivateKey) const; void seedInfo(NewcoinAddress* dstGenerator, BIGNUM** dstPrivateKey) const;
@@ -88,6 +88,7 @@ public:
// //
// Family Generators // Family Generators
// Use to generate a master or regular family.
// //
BIGNUM* getFamilyGeneratorBN() const; BIGNUM* getFamilyGeneratorBN() const;
const std::vector<unsigned char>& getFamilyGenerator() const; const std::vector<unsigned char>& getFamilyGenerator() const;
@@ -114,3 +115,4 @@ public:
}; };
#endif #endif
// vim:ts=4

View File

@@ -7,11 +7,13 @@
#include <iostream> #include <iostream>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <boost/test/included/unit_test.hpp>
namespace po = boost::program_options; namespace po = boost::program_options;
extern bool AddSystemEntropy(); extern bool AddSystemEntropy();
using namespace std; using namespace std;
using namespace boost; using namespace boost::unit_test;
void startServer() void startServer()
{ {
@@ -19,6 +21,14 @@ void startServer()
theApp->run(); // Blocks till we get a stop RPC. theApp->run(); // Blocks till we get a stop RPC.
} }
bool init_unit_test()
{
nothing();
return true;
}
void printHelp(const po::options_description& desc) void printHelp(const po::options_description& desc)
{ {
cout << "newcoin [options] <command> <params>" << endl; cout << "newcoin [options] <command> <params>" << endl;
@@ -56,11 +66,14 @@ int main(int argc, char* argv[])
po::options_description desc("Options"); po::options_description desc("Options");
desc.add_options() desc.add_options()
("help,h", "Display this message.") ("help,h", "Display this message.")
("command", po::value< vector<string> >(), "Specify a comma seperated RPC command.") ("rpc", "Perform rpc command (default).")
("test,t", "Perform unit tests.")
("parameters", po::value< vector<string> >(), "Specify comma seperated parameters.")
; ;
// Interpert positional arguments as --parameters.
po::positional_options_description p; po::positional_options_description p;
p.add("command", -1); p.add("parameters", -1);
// //
// Prepare to run // Prepare to run
@@ -78,7 +91,7 @@ int main(int argc, char* argv[])
{ {
po::store(po::command_line_parser(argc, argv) po::store(po::command_line_parser(argc, argv)
.options(desc) // Parse options. .options(desc) // Parse options.
.positional(p) // Remainder as --command. .positional(p) // Remainder as --parameters.
.run(), .run(),
vm); vm);
po::notify(vm); // Invoke option notify functions. po::notify(vm); // Invoke option notify functions.
@@ -92,7 +105,22 @@ int main(int argc, char* argv[])
{ {
iResult = 1; iResult = 1;
} }
else if (!vm.count("command")) else if (vm.count("test"))
{
std::vector<std::string> vCmd;
int iCmd = vm.count("parameters");
if (iCmd)
vCmd = vm["parameters"].as<std::vector<std::string> >();
char* pvCmd[iCmd];
for (int i=0; i != iCmd; ++i)
pvCmd[i] = (char*) (vCmd[0].c_str());
iResult = unit_test_main(init_unit_test, iCmd, pvCmd);
}
else if (!vm.count("parameters"))
{ {
// No arguments. Run server. // No arguments. Run server.
startServer(); startServer();
@@ -100,7 +128,7 @@ int main(int argc, char* argv[])
else else
{ {
// Have a RPC command. // Have a RPC command.
std::vector<std::string> vCmd = vm["command"].as<std::vector<std::string> >(); std::vector<std::string> vCmd = vm["parameters"].as<std::vector<std::string> >();
iResult = commandLineRPC(vCmd); iResult = commandLineRPC(vCmd);
} }