Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
cybozu::test::AutoRun Class Reference

#include <test.hpp>

Public Member Functions

 AutoRun ()
 
void setup (Func init, Func term)
 
void append (const char *name, Func func)
 
void set (bool isOK)
 
std::string getBaseName (const std::string &name) const
 
int run (int, char *argv[])
 
 AutoRun ()
 
void setup (Func init, Func term)
 
void append (const char *name, Func func)
 
void set (bool isOK)
 
std::string getBaseName (const std::string &name) const
 
int run (int, char *argv[])
 

Static Public Member Functions

static AutoRungetInstance ()
 
static AutoRungetInstance ()
 

Detailed Description

Definition at line 23 of file test.hpp.

Constructor & Destructor Documentation

◆ AutoRun() [1/2]

cybozu::test::AutoRun::AutoRun ( )
inline

Definition at line 27 of file test.hpp.

28 : init_(0)
29 , term_(0)
30 , okCount_(0)
31 , ngCount_(0)
32 , exceptionCount_(0)
33 {
34 }

◆ AutoRun() [2/2]

cybozu::test::AutoRun::AutoRun ( )
inline

Definition at line 27 of file test.hpp.

28 : init_(0)
29 , term_(0)
30 , okCount_(0)
31 , ngCount_(0)
32 , exceptionCount_(0)
33 {
34 }

Member Function Documentation

◆ append() [1/2]

void cybozu::test::AutoRun::append ( const char * name,
Func func )
inline

Definition at line 40 of file test.hpp.

41 {
42 list_.push_back(std::make_pair(name, func));
43 }
std::string name

◆ append() [2/2]

void cybozu::test::AutoRun::append ( const char * name,
Func func )
inline

Definition at line 40 of file test.hpp.

41 {
42 list_.push_back(std::make_pair(name, func));
43 }

◆ getBaseName() [1/2]

std::string cybozu::test::AutoRun::getBaseName ( const std::string & name) const
inline

Definition at line 52 of file test.hpp.

53 {
54#ifdef _WIN32
55 const char sep = '\\';
56#else
57 const char sep = '/';
58#endif
59 size_t pos = name.find_last_of(sep);
60 std::string ret = name.substr(pos + 1);
61 pos = ret.find('.');
62 return ret.substr(0, pos);
63 }
CK_RV ret
Here is the caller graph for this function:

◆ getBaseName() [2/2]

std::string cybozu::test::AutoRun::getBaseName ( const std::string & name) const
inline

Definition at line 52 of file test.hpp.

53 {
54#ifdef _WIN32
55 const char sep = '\\';
56#else
57 const char sep = '/';
58#endif
59 size_t pos = name.find_last_of(sep);
60 std::string ret = name.substr(pos + 1);
61 pos = ret.find('.');
62 return ret.substr(0, pos);
63 }

◆ getInstance() [1/2]

static AutoRun & cybozu::test::AutoRun::getInstance ( )
inlinestatic

Definition at line 101 of file test.hpp.

102 {
103 static AutoRun instance;
104 return instance;
105 }

◆ getInstance() [2/2]

static AutoRun & cybozu::test::AutoRun::getInstance ( )
inlinestatic

Definition at line 103 of file test.hpp.

104 {
105 static AutoRun instance;
106 return instance;
107 }

◆ run() [1/2]

int cybozu::test::AutoRun::run ( int ,
char * argv[] )
inline

Definition at line 64 of file test.hpp.

65 {
66 std::string msg;
67 try {
68 if (init_) init_();
69 for (UnitTestList::const_iterator i = list_.begin(), ie = list_.end(); i != ie; ++i) {
70 std::cout << "ctest:module=" << i->first << std::endl;
71 try {
72 (i->second)();
73 } catch (std::exception& e) {
74 exceptionCount_++;
75 std::cout << "ctest: " << i->first << " is stopped by exception " << e.what() << std::endl;
76 } catch (...) {
77 exceptionCount_++;
78 std::cout << "ctest: " << i->first << " is stopped by unknown exception" << std::endl;
79 }
80 }
81 if (term_) term_();
82 } catch (std::exception& e) {
83 msg = std::string("ctest:err:") + e.what();
84 } catch (...) {
85 msg = "ctest:err: catch unknown exception";
86 }
87 fflush(stdout);
88 if (msg.empty()) {
89 std::cout << "ctest:name=" << getBaseName(*argv)
90 << ", module=" << list_.size()
91 << ", total=" << (okCount_ + ngCount_ + exceptionCount_)
92 << ", ok=" << okCount_
93 << ", ng=" << ngCount_
94 << ", exception=" << exceptionCount_ << std::endl;
95 return 0;
96 } else {
97 std::cout << msg << std::endl;
98 return 1;
99 }
100 }
std::string getBaseName(const std::string &name) const
Definition test.hpp:52
char ** argv
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run() [2/2]

int cybozu::test::AutoRun::run ( int ,
char * argv[] )
inline

Definition at line 64 of file test.hpp.

65 {
66 std::string msg;
67 try {
68 if (init_) init_();
69 for (UnitTestList::const_iterator i = list_.begin(), ie = list_.end(); i != ie; ++i) {
70 std::cout << "ctest:module=" << i->first << std::endl;
71 try {
72 (i->second)();
73 } catch (std::exception& e) {
74 exceptionCount_++;
75 std::cout << "ctest: " << i->first << " is stopped by exception " << e.what() << std::endl;
76 } catch (...) {
77 exceptionCount_++;
78 std::cout << "ctest: " << i->first << " is stopped by unknown exception" << std::endl;
79 }
80 }
81 if (term_) term_();
82 } catch (std::exception& e) {
83 msg = std::string("ctest:err:") + e.what();
84 } catch (...) {
85 msg = "ctest:err: catch unknown exception";
86 }
87 fflush(stdout);
88 if (msg.empty()) {
89 int err = ngCount_ + exceptionCount_;
90 int total = okCount_ + err;
91 std::cout << "ctest:name=" << getBaseName(*argv)
92 << ", module=" << list_.size()
93 << ", total=" << total
94 << ", ok=" << okCount_
95 << ", ng=" << ngCount_
96 << ", exception=" << exceptionCount_ << std::endl;
97 return err > 0 ? 1 : 0;
98 } else {
99 std::cout << msg << std::endl;
100 return 1;
101 }
102 }
Here is the call graph for this function:

◆ set() [1/2]

void cybozu::test::AutoRun::set ( bool isOK)
inline

Definition at line 44 of file test.hpp.

45 {
46 if (isOK) {
47 okCount_++;
48 } else {
49 ngCount_++;
50 }
51 }
Here is the caller graph for this function:

◆ set() [2/2]

void cybozu::test::AutoRun::set ( bool isOK)
inline

Definition at line 44 of file test.hpp.

45 {
46 if (isOK) {
47 okCount_++;
48 } else {
49 ngCount_++;
50 }
51 }

◆ setup() [1/2]

void cybozu::test::AutoRun::setup ( Func init,
Func term )
inline

Definition at line 35 of file test.hpp.

36 {
37 init_ = init;
38 term_ = term;
39 }
void init()
Definition lib_test.cpp:3
Here is the call graph for this function:

◆ setup() [2/2]

void cybozu::test::AutoRun::setup ( Func init,
Func term )
inline

Definition at line 35 of file test.hpp.

36 {
37 init_ = init;
38 term_ = term;
39 }
Here is the call graph for this function:

The documentation for this class was generated from the following files: