[Liblas-commits] hg: 2 new changesets
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Dec 30 18:47:46 EST 2009
changeset 43f8164e7c3c in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=43f8164e7c3c
summary: Updated C++ TUT framework to most recent release
changeset ec1cbc4d7b1a in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=ec1cbc4d7b1a
summary: Cleaned warnings in unit tests to make GCC 4.4.1 proud and happy
diffstat:
test/unit/lasheader_test.cpp | 41 ++-
test/unit/tut/tut_cppunit_reporter.hpp | 201 ++++++++++++++++++
test/unit/tut/tut_restartable.hpp | 28 +-
test/unit/tut/tut_xml_reporter.hpp | 361 +++++++++++++++++++++++++++++++++
4 files changed, 602 insertions(+), 29 deletions(-)
diffs (truncated from 741 to 300 lines):
diff -r f3b481d2694b -r ec1cbc4d7b1a test/unit/lasheader_test.cpp
--- a/test/unit/lasheader_test.cpp Wed Dec 30 23:39:27 2009 +0000
+++ b/test/unit/lasheader_test.cpp Wed Dec 30 23:47:27 2009 +0000
@@ -50,13 +50,13 @@
h1.SetFileSignature(sig);
ensure_not(h1.GetFileSignature() == sig);
- ensure_equals(h1.GetFileSignature().size(), 4);
+ ensure_equals(h1.GetFileSignature().size(), std::string::size_type(4));
ensure_equals(h1.GetFileSignature(), LASHeader::FileSignature);
LASHeader h2(h1);
ensure_not(h2.GetFileSignature() == sig);
- ensure_equals(h2.GetFileSignature().size(), 4);
+ ensure_equals(h2.GetFileSignature().size(), std::string::size_type(4));
ensure_equals(h2.GetFileSignature(), LASHeader::FileSignature);
}
@@ -87,14 +87,14 @@
h1.SetFileSignature(sig);
ensure_not(h1.GetFileSignature() == sig);
- ensure_equals(h1.GetFileSignature().size(), 4);
+ ensure_equals(h1.GetFileSignature().size(), std::string::size_type(4));
ensure_equals(h1.GetFileSignature(), LASHeader::FileSignature);
LASHeader h2;
h2 = h1;
ensure_not(h2.GetFileSignature() == sig);
- ensure_equals(h2.GetFileSignature().size(), 4);
+ ensure_equals(h2.GetFileSignature().size(), std::string::size_type(4));
ensure_equals(h2.GetFileSignature(), LASHeader::FileSignature);
}
@@ -210,12 +210,12 @@
h.SetSystemId(sysid1);
ensure_equals(h.GetSystemId(), sysid1);
ensure_equals(h.GetSystemId().size(), len1);
- ensure_equals(h.GetSystemId(true).size(), 32);
+ ensure_equals(h.GetSystemId(true).size(), std::string::size_type(32));
h.SetSystemId(sysid2);
ensure_equals(h.GetSystemId(), sysid2);
ensure_equals(h.GetSystemId().size(), len2);
- ensure_equals(h.GetSystemId(true).size(), 32);
+ ensure_equals(h.GetSystemId(true).size(), std::string::size_type(32));
}
// Test Get/SetSoftwareId
@@ -234,12 +234,12 @@
h.SetSoftwareId(softid1);
ensure_equals(h.GetSoftwareId(), softid1);
ensure_equals(h.GetSoftwareId().size(), len1);
- ensure_equals(h.GetSoftwareId(true).size(), 32);
+ ensure_equals(h.GetSoftwareId(true).size(), std::string::size_type(32));
h.SetSoftwareId(softid2);
ensure_equals(h.GetSoftwareId(), softid2);
ensure_equals(h.GetSoftwareId().size(), len2);
- ensure_equals(h.GetSoftwareId(true).size(), 32);
+ ensure_equals(h.GetSoftwareId(true).size(), std::string::size_type(32));
}
// Test GetPointRecordsByReturnCount
@@ -247,28 +247,31 @@
template<>
void to::test<11>()
{
+ typedef ::liblas::LASHeader::RecordsByReturnArray::size_type size_type;
+ typedef ::liblas::uint32_t count_type;
+
liblas::LASHeader h;
- ensure_equals(h.GetPointRecordsByReturnCount().size(), 5);
+ ensure_equals(h.GetPointRecordsByReturnCount().size(), size_type(5));
h.SetPointRecordsByReturnCount(0, 100);
- ensure_equals(h.GetPointRecordsByReturnCount().size(), 5);
- ensure_equals(h.GetPointRecordsByReturnCount().at(0), 100);
+ ensure_equals(h.GetPointRecordsByReturnCount().size(), size_type(5));
+ ensure_equals(h.GetPointRecordsByReturnCount().at(0), count_type(100));
h.SetPointRecordsByReturnCount(1, 101);
- ensure_equals(h.GetPointRecordsByReturnCount().size(), 5);
- ensure_equals(h.GetPointRecordsByReturnCount().at(1), 101);
+ ensure_equals(h.GetPointRecordsByReturnCount().size(), size_type(5));
+ ensure_equals(h.GetPointRecordsByReturnCount().at(1), count_type(101));
h.SetPointRecordsByReturnCount(2, 102);
- ensure_equals(h.GetPointRecordsByReturnCount().size(), 5);
- ensure_equals(h.GetPointRecordsByReturnCount().at(2), 102);
+ ensure_equals(h.GetPointRecordsByReturnCount().size(), size_type(5));
+ ensure_equals(h.GetPointRecordsByReturnCount().at(2), count_type(102));
h.SetPointRecordsByReturnCount(3, 103);
- ensure_equals(h.GetPointRecordsByReturnCount().size(), 5);
- ensure_equals(h.GetPointRecordsByReturnCount().at(3), 103);
+ ensure_equals(h.GetPointRecordsByReturnCount().size(), size_type(5));
+ ensure_equals(h.GetPointRecordsByReturnCount().at(3), count_type(103));
h.SetPointRecordsByReturnCount(4, 104);
- ensure_equals(h.GetPointRecordsByReturnCount().size(), 5);
- ensure_equals(h.GetPointRecordsByReturnCount().at(4), 104);
+ ensure_equals(h.GetPointRecordsByReturnCount().size(), size_type(5));
+ ensure_equals(h.GetPointRecordsByReturnCount().at(4), count_type(104));
try
{
diff -r f3b481d2694b -r ec1cbc4d7b1a test/unit/tut/tut_cppunit_reporter.hpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/unit/tut/tut_cppunit_reporter.hpp Wed Dec 30 23:47:27 2009 +0000
@@ -0,0 +1,201 @@
+
+#ifndef TUT_CPPUNIT_REPORTER
+#define TUT_CPPUNIT_REPORTER
+
+#include <tut/tut.hpp>
+#include <string>
+#include <fstream>
+#include <vector>
+#include <stdexcept>
+
+namespace tut
+{
+
+/**
+ * CppUnit TUT reporter
+ */
+class cppunit_reporter : public tut::callback
+{
+ private:
+ std::vector<tut::test_result> failed_tests;
+ std::vector<tut::test_result> passed_tests;
+ std::string filename;
+
+ std::string encode(const std::string & text)
+ {
+ std::string out;
+
+ for (unsigned int i=0; i<text.length(); ++i) {
+ char c = text[i];
+ switch (c) {
+ case '<':
+ out += "<";
+ break;
+ case '>':
+ out += ">";
+ break;
+ case '&':
+ out += "&";
+ break;
+ case '\'':
+ out += "'";
+ break;
+ case '"':
+ out += """;
+ break;
+ default:
+ out += c;
+ }
+ }
+
+ return out;
+ }
+
+public:
+
+ cppunit_reporter(const std::string & _filename = "")
+ {
+ setFilename(_filename);
+ }
+
+ void setFilename(const std::string & _filename)
+ {
+ if (_filename == "")
+ {
+ filename = "testResult.xml";
+ }
+ else
+ {
+ filename = _filename;
+ }
+ }
+
+ void run_started()
+ {
+ failed_tests.clear();
+ passed_tests.clear();
+ }
+
+ void test_completed(const tut::test_result& tr)
+ {
+ if (tr.result == test_result::ok) {
+ passed_tests.push_back(tr);
+ } else {
+ failed_tests.push_back(tr);
+ }
+ }
+
+ void run_completed()
+ {
+ int errors = 0;
+ int failures = 0;
+ std::string failure_type;
+ std::string failure_msg;
+ std::ofstream xmlfile;
+
+ xmlfile.open(filename.c_str(), std::ios::in | std::ios::trunc);
+ if (!xmlfile.is_open()) {
+ throw (std::runtime_error("Cannot open file for output"));
+ }
+
+ /* *********************** header ***************************** */
+ xmlfile << "<?xml version=\"1.0\" encoding='ISO-8859-1' standalone='yes' ?>" << std::endl
+ << "<TestRun>" << std::endl;
+
+ /* *********************** failed tests ***************************** */
+ if (failed_tests.size() > 0) {
+ xmlfile << " <FailedTests>" << std::endl;
+
+ for (unsigned int i=0; i<failed_tests.size(); i++) {
+ switch (failed_tests[i].result) {
+ case test_result::fail:
+ failure_type = "Assertion";
+ failure_msg = "";
+ failures++;
+ break;
+ case test_result::ex:
+ failure_type = "Assertion";
+ failure_msg = "Thrown exception: " + failed_tests[i].exception_typeid + '\n';
+ failures++;
+ break;
+ case test_result::warn:
+ failure_type = "Assertion";
+ failure_msg = "Destructor failed.\n";
+ failures++;
+ break;
+ case test_result::term:
+ failure_type = "Error";
+ failure_msg = "Test application terminated abnormally.\n";
+ errors++;
+ break;
+ case test_result::ex_ctor:
+ failure_type = "Error";
+ failure_msg = "Constructor has thrown an exception: " + failed_tests[i].exception_typeid + '\n';
+ errors++;
+ break;
+ case test_result::rethrown:
+ failure_type = "Assertion";
+ failure_msg = "Child failed";
+ failures++;
+ break;
+ default:
+ failure_type = "Error";
+ failure_msg = "Unknown test status, this should have never happened. "
+ "You may just have found a BUG in TUT CppUnit reporter, please report it immediately.\n";
+ errors++;
+ break;
+ }
+
+ xmlfile << " <FailedTest id=\"" << failed_tests[i].test << "\">" << std::endl
+ << " <Name>" << encode(failed_tests[i].group) + "::" + encode(failed_tests[i].name) << "</Name>" << std::endl
+ << " <FailureType>" << failure_type << "</FailureType>" << std::endl
+ << " <Location>" << std::endl
+ << " <File>Unknown</File>" << std::endl
+ << " <Line>Unknown</Line>" << std::endl
+ << " </Location>" << std::endl
+ << " <Message>" << encode(failure_msg + failed_tests[i].message) << "</Message>" << std::endl
+ << " </FailedTest>" << std::endl;
+ }
+
+ xmlfile << " </FailedTests>" << std::endl;
+ }
+
+ /* *********************** passed tests ***************************** */
+ if (passed_tests.size() > 0) {
+ xmlfile << " <SuccessfulTests>" << std::endl;
+
+ for (unsigned int i=0; i<passed_tests.size(); i++) {
+ xmlfile << " <Test id=\"" << passed_tests[i].test << "\">" << std::endl
+ << " <Name>" << encode(passed_tests[i].group) + "::" + encode(passed_tests[i].name) << "</Name>" << std::endl
+ << " </Test>" << std::endl;
+ }
+
+ xmlfile << " </SuccessfulTests>" << std::endl;
+ }
+
+ /* *********************** statistics ***************************** */
+ xmlfile << " <Statistics>" << std::endl
+ << " <Tests>" << (failed_tests.size() + passed_tests.size()) << "</Tests>" << std::endl
+ << " <FailuresTotal>" << failed_tests.size() << "</FailuresTotal>" << std::endl
+ << " <Errors>" << errors << "</Errors>" << std::endl
+ << " <Failures>" << failures << "</Failures>" << std::endl
+ << " </Statistics>" << std::endl;
+
+ /* *********************** footer ***************************** */
+ xmlfile << "</TestRun>" << std::endl;
+
+ xmlfile.close();
More information about the Liblas-commits
mailing list