From b369d1baead1128379ecab2ee74d2765c24fffb7 Mon Sep 17 00:00:00 2001 From: joncruz Date: Tue, 4 Apr 2006 09:29:55 +0000 Subject: [PATCH] Converting attributes test to CxxTest --- src/Makefile.am | 10 ++-- src/Makefile_insert | 3 - ...{attributes-test.cpp => attributes-test.h} | 55 +++++++++++-------- 3 files changed, 37 insertions(+), 31 deletions(-) rename src/{attributes-test.cpp => attributes-test.h} (93%) diff --git a/src/Makefile.am b/src/Makefile.am index 6ac221a1a..cf1033881 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -166,7 +166,6 @@ EXTRA_PROGRAMS = \ TESTS = \ test-all$(EXEEXT) \ - attributes-test$(EXEEXT) \ dir-util-test$(EXEEXT) \ extract-uri-test$(EXEEXT) \ mod360-test$(EXEEXT) \ @@ -201,7 +200,6 @@ TESTS = \ check_PROGRAMS = \ test-all \ - attributes-test \ dir-util-test \ extract-uri-test \ mod360-test \ @@ -236,16 +234,20 @@ test-all.cpp: \ $(xml_test_xml_a_SOURCES) \ $(libnr_test_nr_includes) \ $(svg_test_svg_includes) \ - $(xml_test_xml_includes) + $(xml_test_xml_includes) \ + attributes-test.h $(top_srcdir)/cxxtest/cxxtestgen.pl --error-printer -root -o test-all.cpp \ $(libnr_test_nr_includes) \ $(svg_test_svg_includes) \ - $(xml_test_xml_includes) + $(xml_test_xml_includes) \ + attributes-test.h test_all_SOURCES = \ test-all.cpp + test_all_LDADD = \ + libinkpre.a \ $(libnr_test_nr_LDADD) \ $(svg_test_svg_LDADD) \ $(xml_test_xml_LDADD) diff --git a/src/Makefile_insert b/src/Makefile_insert index c552f3401..31f57f33b 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -317,9 +317,6 @@ inkscape_LDFLAGS = --export-dynamic $(kdeldflags) inkview_SOURCES = inkview.cpp $(win32_sources) inkview_LDADD = $(all_libs) -attributes_test_SOURCES = attributes-test.cpp -attributes_test_LDADD = attributes.$(OBJEXT) -lglib-2.0 - dir_util_test_SOURCES = dir-util-test.cpp utest/test-2ary-cases.h dir_util_test_LDADD = dir-util.$(OBJEXT) -lglib-2.0 diff --git a/src/attributes-test.cpp b/src/attributes-test.h similarity index 93% rename from src/attributes-test.cpp rename to src/attributes-test.h index ad640aa88..acd1fc404 100644 --- a/src/attributes-test.cpp +++ b/src/attributes-test.h @@ -1,8 +1,28 @@ + +#include + #include #include "utest/utest.h" #include "attributes.h" #include "streq.h" +class AttributesTest : public CxxTest::TestSuite +{ +public: + + AttributesTest() + { + } + virtual ~AttributesTest() {} + +// createSuite and destroySuite get us per-suite setup and teardown +// without us having to worry about static initialization order, etc. + static AttributesTest *createSuite() { return new AttributesTest(); } + static void destroySuite( AttributesTest *suite ) { delete suite; } + + + void testAttributes() + { /* Extracted mechanically from http://www.w3.org/TR/SVG11/attindex.html: tidy -wrap 999 -asxml < attindex.html 2>/dev/null | @@ -15,7 +35,7 @@ attindex.html lacks attributeName, begin, additive, font, marker; I've added these manually. */ -static struct {char const *attr; bool supported;} const all_attrs[] = { +struct {char const *attr; bool supported;} const all_attrs[] = { {"attributeName", true}, {"begin", true}, {"additive", true}, @@ -396,29 +416,26 @@ static struct {char const *attr; bool supported;} const all_attrs[] = { }; -static bool -test_attributes() -{ - utest_start("attributes"); - std::vector ids; - ids.reserve(256); - UTEST_TEST("attribute lookup") { + + std::vector ids; + ids.reserve(256); + for (unsigned i = 0; i < G_N_ELEMENTS(all_attrs); ++i) { char const *const attr_str = all_attrs[i].attr; unsigned const id = sp_attribute_lookup(attr_str); bool const recognized(id); - UTEST_ASSERT(recognized == all_attrs[i].supported); + TSM_ASSERT_EQUALS( std::string(all_attrs[i].attr), recognized, all_attrs[i].supported ); if (recognized) { if (ids.size() <= id) { ids.resize(id + 1); } - UTEST_ASSERT(!ids[id]); + TS_ASSERT(!ids[id]); ids[id] = true; unsigned char const *reverse_ustr = sp_attribute_name(id); char const *reverse_str = reinterpret_cast(reverse_ustr); - UTEST_ASSERT(streq(reverse_str, attr_str)); + TS_ASSERT(streq(reverse_str, attr_str)); } } @@ -450,23 +467,13 @@ test_attributes() unsigned const n_ids = ids.size(); for (unsigned id = 1; id < n_ids; ++id) { if (!ids[id]) { - unsigned char const *str = sp_attribute_name(id); - printf("%s\n", (const char *)str); /* Apparently printf doesn't like unsigned strings -- Ted */ + TS_WARN( std::string((const char*)sp_attribute_name(id)) ); found = true; } } - UTEST_ASSERT(!found); + TS_ASSERT(!found); } - - return utest_end(); -} - -int main() -{ - return ( test_attributes() - ? EXIT_SUCCESS - : EXIT_FAILURE ); -} +}; /* Local Variables: -- 2.39.5