Improved test support.
This commit is contained in:
parent
ec467953bc
commit
c7b77ae329
@ -1,14 +1,22 @@
|
|||||||
TESTS = $(check_PROGRAMS)
|
TESTS = $(check_PROGRAMS)
|
||||||
check_PROGRAMS = seeded_hash_test mph_bits_test hollow_iterator_test mph_map_test mph_index_test trigraph_test map_tester_test string_util_test
|
check_PROGRAMS = test_test seeded_hash_test mph_bits_test hollow_iterator_test mph_map_test mph_index_test trigraph_test map_tester_test string_util_test
|
||||||
noinst_PROGRAMS = bm_index bm_map
|
noinst_PROGRAMS = bm_index bm_map
|
||||||
bin_PROGRAMS = cxxmph
|
bin_PROGRAMS = cxxmph
|
||||||
lib_LTLIBRARIES = libcxxmph.la
|
|
||||||
libcxxmph_la_SOURCES = MurmurHash3.h MurmurHash3.cpp trigragh.h trigraph.cc mph_bits.h mph_bits.cc mph_index.h mph_index.cc seeded_hash.h stringpiece.h benchmark.h benchmark.cc string_util.cc
|
|
||||||
libcxxmph_la_LDFLAGS = -version-info 0:0:0
|
|
||||||
cxxmph_includedir = $(includedir)/cxxmph/
|
cxxmph_includedir = $(includedir)/cxxmph/
|
||||||
cxxmph_include_HEADERS = mph_map.h mph_index.h MurmurHash3.h trigraph.h seeded_hash.h stringpiece.h hollow_iterator.h
|
cxxmph_include_HEADERS = mph_map.h mph_index.h MurmurHash3.h trigraph.h seeded_hash.h stringpiece.h hollow_iterator.h
|
||||||
|
|
||||||
mph_map_test_LDADD = libcxxmph.la
|
noinst_LTLIBRARIES = libcxxmph_test.la
|
||||||
|
lib_LTLIBRARIES = libcxxmph.la
|
||||||
|
libcxxmph_la_SOURCES = MurmurHash3.h MurmurHash3.cpp trigragh.h trigraph.cc mph_bits.h mph_bits.cc mph_index.h mph_index.cc seeded_hash.h stringpiece.h benchmark.h benchmark.cc string_util.cc
|
||||||
|
libcxxmph_la_LDFLAGS = -version-info 0:0:0
|
||||||
|
libcxxmph_test_la_SOURCES = test.h test.cc
|
||||||
|
libcxxmph_test_la_LIBADD = libcxxmph.la
|
||||||
|
|
||||||
|
test_test_SOURCES = test_test.cc
|
||||||
|
test_test_LDADD = libcxxmph_test.la $(CHECK_LIBS)
|
||||||
|
|
||||||
|
mph_map_test_LDADD = libcxxmph_test.la $(CHECK_LIBS)
|
||||||
mph_map_test_SOURCES = mph_map_test.cc
|
mph_map_test_SOURCES = mph_map_test.cc
|
||||||
|
|
||||||
mph_index_test_LDADD = libcxxmph.la
|
mph_index_test_LDADD = libcxxmph.la
|
||||||
@ -38,5 +46,5 @@ string_util_test_SOURCES = string_util_test.cc
|
|||||||
string_util_test_LDADD = libcxxmph.la
|
string_util_test_LDADD = libcxxmph.la
|
||||||
|
|
||||||
map_tester_test_SOURCES = map_tester.cc map_tester_test.cc
|
map_tester_test_SOURCES = map_tester.cc map_tester_test.cc
|
||||||
map_tester_test_LDADD = $(CHECK_LIBS)
|
map_tester_test_LDADD = libcxxmph.la libcxxmph_test.la $(CHECK_LIBS)
|
||||||
|
|
||||||
|
@ -14,21 +14,7 @@ namespace cxxmph {
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
template <template<typename...> class map_type>
|
template <template<typename...> class map_type>
|
||||||
class MapTester {
|
struct MapTester {
|
||||||
public:
|
|
||||||
MapTester() {}
|
|
||||||
~MapTester() {}
|
|
||||||
|
|
||||||
bool Run(string* errors) const {
|
|
||||||
string e;
|
|
||||||
if (!small_insert()) e += "small insert failed\n";
|
|
||||||
if (!large_insert()) e += "large insert failed\n";
|
|
||||||
if (!small_search()) e += "small search failed\n";
|
|
||||||
if (!default_search()) e += "default search failed\n";
|
|
||||||
if (!large_search()) e += "large search failed\n";
|
|
||||||
if (errors) *errors = e;
|
|
||||||
return !e.empty();
|
|
||||||
}
|
|
||||||
static bool small_insert() {
|
static bool small_insert() {
|
||||||
map_type<int64_t, int64_t> m;
|
map_type<int64_t, int64_t> m;
|
||||||
// Start counting from 1 to not touch default constructed value bugs
|
// Start counting from 1 to not touch default constructed value bugs
|
||||||
@ -68,9 +54,7 @@ class MapTester {
|
|||||||
int nkeys = 10 * 1000;
|
int nkeys = 10 * 1000;
|
||||||
vector<string> keys;
|
vector<string> keys;
|
||||||
for (int i = 0; i < nkeys; ++i) {
|
for (int i = 0; i < nkeys; ++i) {
|
||||||
char buf[128];
|
keys.push_back(cxxmph::format("%v", i));
|
||||||
cxxmph::format("%v", i);
|
|
||||||
keys.push_back(buf);
|
|
||||||
}
|
}
|
||||||
map_type<string, int64_t> m;
|
map_type<string, int64_t> m;
|
||||||
for (int i = 0; i < nkeys; ++i) m.insert(make_pair(keys[i], i));
|
for (int i = 0; i < nkeys; ++i) m.insert(make_pair(keys[i], i));
|
||||||
|
@ -1,28 +1,13 @@
|
|||||||
#include "map_tester.h"
|
#include "map_tester.h"
|
||||||
#include <check.h>
|
#include "test.h"
|
||||||
|
|
||||||
using namespace cxxmph;
|
using namespace cxxmph;
|
||||||
|
|
||||||
START_TEST(search) {
|
typedef MapTester<std::unordered_map> Tester;
|
||||||
MapTester<std::unordered_map> tester;
|
|
||||||
|
|
||||||
} END_TEST
|
CXXMPH_CXX_TEST_CASE(small_insert, Tester::small_insert);
|
||||||
|
CXXMPH_CXX_TEST_CASE(large_insert, Tester::large_insert);
|
||||||
Suite *MapTesterSuite() {
|
CXXMPH_CXX_TEST_CASE(small_search, Tester::small_search);
|
||||||
Suite *s = suite_create ("MapTester");
|
CXXMPH_CXX_TEST_CASE(default_search, Tester::default_search);
|
||||||
/* Core test case */
|
CXXMPH_CXX_TEST_CASE(large_search, Tester::large_search);
|
||||||
TCase *tc_core = tcase_create ("Core");
|
CXXMPH_CXX_TEST_CASE(string_search, Tester::string_search);
|
||||||
tcase_add_test (tc_core, search);
|
|
||||||
suite_add_tcase (s, tc_core);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main (void) {
|
|
||||||
int number_failed;
|
|
||||||
Suite *s = MapTesterSuite();
|
|
||||||
SRunner *sr = srunner_create (s);
|
|
||||||
srunner_run_all (sr, CK_NORMAL);
|
|
||||||
number_failed = srunner_ntests_failed (sr);
|
|
||||||
srunner_free (sr);
|
|
||||||
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
@ -4,7 +4,21 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "mph_map.h"
|
#include "mph_map.h"
|
||||||
|
#include "map_tester.h"
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
using namespace cxxmph;
|
||||||
|
|
||||||
|
typedef MapTester<mph_map> Tester;
|
||||||
|
|
||||||
|
CXXMPH_CXX_TEST_CASE(small_insert, Tester::small_insert);
|
||||||
|
CXXMPH_CXX_TEST_CASE(large_insert, Tester::large_insert);
|
||||||
|
CXXMPH_CXX_TEST_CASE(small_search, Tester::small_search);
|
||||||
|
CXXMPH_CXX_TEST_CASE(default_search, Tester::default_search);
|
||||||
|
CXXMPH_CXX_TEST_CASE(large_search, Tester::large_search);
|
||||||
|
CXXMPH_CXX_TEST_CASE(string_search, Tester::string_search);
|
||||||
|
|
||||||
|
/*
|
||||||
using std::make_pair;
|
using std::make_pair;
|
||||||
using std::string;
|
using std::string;
|
||||||
using cxxmph::mph_map;
|
using cxxmph::mph_map;
|
||||||
@ -27,7 +41,6 @@ int main(int argc, char** argv) {
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
mph_map<string, int> h;
|
mph_map<string, int> h;
|
||||||
h.insert(std::make_pair("-1",-1));
|
h.insert(std::make_pair("-1",-1));
|
||||||
mph_map<string, int>::const_iterator it;
|
mph_map<string, int>::const_iterator it;
|
||||||
@ -57,5 +70,5 @@ int main(int argc, char** argv) {
|
|||||||
if (key < num_valid && it->second != key) exit(-1);
|
if (key < num_valid && it->second != key) exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
16
cxxmph/test.cc
Normal file
16
cxxmph/test.cc
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <cstdlib> // For EXIT_SUCCESS, EXIT_FAILURE
|
||||||
|
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
Suite* global_suite = suite_create("cxxmph_test_suite");
|
||||||
|
TCase* global_tc_core = tcase_create("Core");
|
||||||
|
|
||||||
|
int main (void) {
|
||||||
|
suite_add_tcase(global_suite, global_tc_core);
|
||||||
|
int number_failed;
|
||||||
|
SRunner *sr = srunner_create (global_suite);
|
||||||
|
srunner_run_all (sr, CK_NORMAL);
|
||||||
|
number_failed = srunner_ntests_failed (sr);
|
||||||
|
srunner_free (sr);
|
||||||
|
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
|
}
|
31
cxxmph/test.h
Normal file
31
cxxmph/test.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef __CXXMPH_TEST_H__
|
||||||
|
#define __CXXMPH_TEST_H__
|
||||||
|
|
||||||
|
// Thin wrapper on top of check.h to get rid of boilerplate in tests. Assumes a
|
||||||
|
// single test suite and test case per file, with each fixture represented by a
|
||||||
|
// parameter-less boolean function.
|
||||||
|
//
|
||||||
|
// The check.h header macro-clashes with c++ libraries so this file needs to be
|
||||||
|
// included last.
|
||||||
|
|
||||||
|
#include <check.h>
|
||||||
|
|
||||||
|
extern Suite* global_suite;
|
||||||
|
extern TCase* global_tc_core;
|
||||||
|
|
||||||
|
// Creates a new test case calling boolean_function. Name must be a valid,
|
||||||
|
// unique c identifier when prefixed with tc_.
|
||||||
|
#define CXXMPH_CXX_TEST_CASE(name, boolean_function) \
|
||||||
|
START_TEST(tc_ ## name) \
|
||||||
|
{ fail_unless(boolean_function()); } END_TEST \
|
||||||
|
static TestCase global_cxxmph_tc_ ## name(tc_ ## name);
|
||||||
|
|
||||||
|
#define CXXMPH_TEST_CASE(name) CXXMPH_CXX_TEST_CASE(name, name)
|
||||||
|
|
||||||
|
struct TestCase {
|
||||||
|
TestCase(void (*f)(int)) {
|
||||||
|
tcase_add_test(global_tc_core, f);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // __CXXMPH_TEST_H__
|
4
cxxmph/test_test.cc
Normal file
4
cxxmph/test_test.cc
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
bool tautology() { return true; }
|
||||||
|
CXXMPH_TEST_CASE(tautology)
|
Loading…
Reference in New Issue
Block a user