1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 * Data Differential YATL (i.e. libtest) library
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include "libtest/yatlcon.h"
39 #include <libtest/common.h>
40 #include <libtest/collection.h>
41 #include <libtest/signal.h>
49 Framework::Framework(libtest::SignalThread
& signal_
,
50 const std::string
& name_
,
51 const std::string
& only_run_arg
,
52 const std::string
& wildcard_arg
) :
64 _only_run(only_run_arg
),
65 _wildcard(wildcard_arg
),
71 void Framework::collections(collection_st collections_
[])
73 for (collection_st
*next
= collections_
; next
and next
->name
; next
++)
75 _collection
.push_back(new Collection(this, next
));
79 Framework::~Framework()
81 if (_destroy
and _destroy(_creators_ptr
))
83 Error
<< "Failure in _destroy(), some resources may not have been cleaned up.";
90 std::for_each(_collection
.begin(), _collection
.end(), DeleteFromVector());
94 bool Framework::match(const char* arg
)
96 if (_wildcard
.empty() == false and fnmatch(_wildcard
.c_str(), arg
, 0))
104 void Framework::exec()
106 for (std::vector
<Collection
*>::iterator iter
= _collection
.begin();
107 iter
!= _collection
.end() and (_signal
.is_shutdown() == false);
112 if (_only_run
.empty() == false and
113 fnmatch(_only_run
.c_str(), (*iter
)->name(), 0))
121 switch ((*iter
)->exec())
131 // exec() can return SUCCESS, but that doesn't mean that some tests did
132 // not fail or get skipped.
138 catch (const libtest::fatal
& e
)
141 stream::cerr(e
.file(), e
.line(), e
.func()) << e
.what();
143 catch (const libtest::disconnected
& e
)
146 Error
<< "Unhandled disconnection occurred:" << e
.what();
157 void xml(const std::string
& testsuites_name
, std::ostream
& output
);
160 uint32_t Framework::sum_total()
163 for (std::vector
<Collection
*>::iterator iter
= _collection
.begin();
164 iter
!= _collection
.end();
167 count
+= (*iter
)->total();
173 uint32_t Framework::sum_success()
176 for (std::vector
<Collection
*>::iterator iter
= _collection
.begin();
177 iter
!= _collection
.end();
180 count
+= (*iter
)->success();
186 uint32_t Framework::sum_skipped()
189 for (std::vector
<Collection
*>::iterator iter
= _collection
.begin();
190 iter
!= _collection
.end();
193 count
+= (*iter
)->skipped();
199 uint32_t Framework::sum_failed()
202 for (std::vector
<Collection
*>::iterator iter
= _collection
.begin();
203 iter
!= _collection
.end();
206 count
+= (*iter
)->failed();
212 libtest::Runner
*Framework::runner()
218 _runner
->set_servers(_servers
);
223 test_return_t
Framework::create()
225 test_return_t rc
= TEST_SUCCESS
;
228 _creators_ptr
= _create(_servers
, rc
);
234 } // namespace libtest