From 318a44757d7be4f4885b502e46f98eb37b53a839 Mon Sep 17 00:00:00 2001 From: randomdan Date: Thu, 6 Nov 2014 01:14:42 +0000 Subject: Big refactor to use Boost UTF --- slicer/test/Jamfile.jam | 41 +++--- slicer/test/conversions.cpp | 47 +++++++ slicer/test/do-slicer.cpp | 89 ------------- slicer/test/fileStructure.cpp | 23 ++++ slicer/test/fileStructure.h | 25 ++++ slicer/test/preprocessor.cpp | 50 +++++++ slicer/test/run-slicer.cpp | 289 ----------------------------------------- slicer/test/serializers.cpp | 293 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 461 insertions(+), 396 deletions(-) create mode 100644 slicer/test/conversions.cpp delete mode 100644 slicer/test/do-slicer.cpp create mode 100644 slicer/test/fileStructure.cpp create mode 100644 slicer/test/fileStructure.h create mode 100644 slicer/test/preprocessor.cpp delete mode 100644 slicer/test/run-slicer.cpp create mode 100644 slicer/test/serializers.cpp diff --git a/slicer/test/Jamfile.jam b/slicer/test/Jamfile.jam index 4a149a8..ffedb00 100644 --- a/slicer/test/Jamfile.jam +++ b/slicer/test/Jamfile.jam @@ -6,6 +6,7 @@ lib Ice ; lib IceUtil ; lib boost_system ; lib boost_filesystem ; +lib boost_utf : : boost_unit_test_framework ; lib slicer-test : : slicertypes bin/slicer ; lib types : @@ -14,49 +15,53 @@ lib types : pthread Ice IceUtil + : : + pthread + Ice + IceUtil ; lib common : helpers.cpp + conversions.cpp + fileStructure.cpp ../../libmisc/misc.cpp : dl + types boost_system boost_filesystem + boost_utf + types : : + types boost_filesystem boost_system ../../libmisc + BOOST_TEST_DYN_LINK + boost_utf + types ; -unit-test do-slicer : - types - common - do-slicer.cpp +unit-test preprocess : + preprocessor.cpp : -rdynamic dl + common .. - pthread - Ice - IceUtil ../slicer//slicer - types ; -unit-test run-slicer : - run-slicer.cpp - types - common +unit-test serializers : + serializers.cpp : - types - do-slicer + preprocess slicer-test + common .. - pthread - Ice - IceUtil ../slicer//slicer ../xml//slicer-xml ../json//slicer-json -; + ; + diff --git a/slicer/test/conversions.cpp b/slicer/test/conversions.cpp new file mode 100644 index 0000000..a6c2c06 --- /dev/null +++ b/slicer/test/conversions.cpp @@ -0,0 +1,47 @@ +#include "types.h" +#include + +#define SHORT(x) boost::numeric_cast< ::Ice::Short >(x) + +namespace Slicer { + boost::posix_time::ptime + dateTimeToPTime(const ::TestModule::DateTime &) + { + throw std::runtime_error("Not implemented"); + } + + ::TestModule::DateTime + ptimeToDateTime(const boost::posix_time::ptime &) + { + throw std::runtime_error("Not implemented"); + } + + std::string + dateTimeToString(const ::TestModule::DateTime & in) + { + char buf[BUFSIZ]; + struct tm tm({ in.second, in.minute, in.hour, in.day, in.month, in.year, 0, 0, 0 +#ifdef _BSD_SOURCE + , 0, 0 +#endif + }); + mktime(&tm); + auto len = strftime(buf, BUFSIZ, "%Y-%b-%d %H:%M:%S", &tm); + return std::string(buf, len); + } + + ::TestModule::DateTime + stringToDateTime(const std::string & in) + { + struct tm tm; + memset(&tm, 0, sizeof(struct tm)); + auto end = strptime(in.c_str(), "%Y-%b-%d %H:%M:%S", &tm); + if (!end || *end) { + throw std::runtime_error("Invalid date string: " + in); + } + return ::TestModule::DateTime({ + SHORT(tm.tm_year), SHORT(tm.tm_mon), SHORT(tm.tm_mday), + SHORT(tm.tm_hour), SHORT(tm.tm_min), SHORT(tm.tm_sec)}); + } +} + diff --git a/slicer/test/do-slicer.cpp b/slicer/test/do-slicer.cpp deleted file mode 100644 index 7607ff2..0000000 --- a/slicer/test/do-slicer.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include -#include -#include -#include -#include -#include "../../libmisc/misc.h" -#include -#include "helpers.h" - -namespace fs = boost::filesystem; - -namespace Slicer { - // These are the conversion helpers defined used in types.ice, they're not called in this test, but - // need to exist for the dynamic load to complete - boost::posix_time::ptime - dateTimeToPTime(const ::TestModule::DateTime &) - { - throw std::runtime_error("Not implemented"); - } - - ::TestModule::DateTime - ptimeToDateTime(const boost::posix_time::ptime &) - { - throw std::runtime_error("Not implemented"); - } - - std::string - dateTimeToString(const ::TestModule::DateTime &) - { - throw std::runtime_error("Not implemented"); - } - - ::TestModule::DateTime - stringToDateTime(const std::string &) - { - throw std::runtime_error("Not implemented"); - } -} - -int -main(int, char ** argv) -{ - const fs::path me = argv[0]; - const fs::path base = "types"; - const fs::path bjamout = me.parent_path(); - const fs::path root = me.parent_path().parent_path().parent_path().parent_path(); - fprintf(stderr, "root -- %s\n", root.string().c_str()); - const fs::path slice = fs::change_extension(root / base, ".ice"); - fprintf(stderr, "slice - %s\n", slice.string().c_str()); - - // Tmp - const fs::path tmp = root / "bin" / "slicer"; - fprintf(stderr, "tmp --- %s\n", tmp.string().c_str()); - fs::create_directory(tmp); - - // Slicer - const fs::path cpp = fs::change_extension(tmp / base, ".cpp"); - fprintf(stderr, "cpp --- %s\n", cpp.string().c_str()); - fs::remove(cpp); - Slicer::Slicer::Apply(slice, cpp); - - // Compile - const fs::path obj = fs::change_extension(tmp / base, ".o"); - fprintf(stderr, "obj --- %s\n", obj.string().c_str()); - system(stringbf( - "g++ -Os -fPIC -c -std=c++0x -I tmp -I /usr/include/Ice -I /usr/include/IceUtil -I %s -I %s %s -o %s", - bjamout, - root / "..", - cpp, obj)); - - // Link - const fs::path so = fs::change_extension(tmp / ("libslicer" + slice.filename().string()), ".so"); - fprintf(stderr, "so ---- %s\n", so.string().c_str()); - system(stringbf( - "g++ -shared -lIce -lIceUtil %s/lib%s.so %s -o %s", - bjamout, base, - obj, so)); - - // Load - fprintf(stderr, "load -- %s\n", so.string().c_str()); - auto handle = loadlib(so); - - // Unload - fprintf(stderr, "unload %p\n", handle); - closelib(handle); - - return 0; -} - diff --git a/slicer/test/fileStructure.cpp b/slicer/test/fileStructure.cpp new file mode 100644 index 0000000..d586786 --- /dev/null +++ b/slicer/test/fileStructure.cpp @@ -0,0 +1,23 @@ +#include "fileStructure.h" +#include +#include + +FileStructure::FileStructure() : + me(boost::filesystem::canonical("/proc/self/exe")), + base("types"), + bjamout(me.parent_path()), + root(me.parent_path().parent_path().parent_path().parent_path()), + slice(fs::change_extension(root / base, ".ice")), + tmp(root / "bin" / "slicer"), + tmpf(tmp / "byFile"), + tmph(tmp / "byHelper") +{ + fs::create_directory(tmp); + fs::create_directory(tmpf); + fs::create_directory(tmph); +} + +FileStructure::~FileStructure() +{ +} + diff --git a/slicer/test/fileStructure.h b/slicer/test/fileStructure.h new file mode 100644 index 0000000..475146c --- /dev/null +++ b/slicer/test/fileStructure.h @@ -0,0 +1,25 @@ +#ifndef SLICER_TEST_FILESTRUCTURE +#define SLICER_TEST_FILESTRUCTURE + +#include + +namespace fs = boost::filesystem; + +class FileStructure { + public: + FileStructure(); + ~FileStructure(); + + protected: + const fs::path me; + const fs::path base; + const fs::path bjamout; + const fs::path root; + const fs::path slice; + const fs::path tmp; + const fs::path tmpf; + const fs::path tmph; +}; + +#endif + diff --git a/slicer/test/preprocessor.cpp b/slicer/test/preprocessor.cpp new file mode 100644 index 0000000..f4c75fc --- /dev/null +++ b/slicer/test/preprocessor.cpp @@ -0,0 +1,50 @@ +#define BOOST_TEST_MODULE preprocess +#include + +#include +#include +#include +#include +#include +#include +#include +#include "helpers.h" +#include "fileStructure.h" + +namespace fs = boost::filesystem; + +BOOST_FIXTURE_TEST_SUITE ( preprocessor, FileStructure ); + +BOOST_AUTO_TEST_CASE( slicer_test_ice ) +{ + const fs::path cpp = fs::change_extension(tmp / base, ".cpp"); + BOOST_TEST_CHECKPOINT("cpp: " << cpp); + fs::remove(cpp); + Slicer::Slicer::Apply(slice, cpp); + + const fs::path obj = fs::change_extension(tmp / base, ".o"); + const std::string compile = stringbf( + "g++ -Os -fPIC -c -std=c++0x -I tmp -I /usr/include/Ice -I /usr/include/IceUtil -I %s -I %s %s -o %s", + bjamout, + root / "..", + cpp, obj); + BOOST_TEST_CHECKPOINT("compile: " << compile); + system(compile); + + const fs::path so = fs::change_extension(tmp / ("libslicer" + slice.filename().string()), ".so"); + const std::string link = stringbf( + "g++ -shared -lIce -lIceUtil %s/lib%s.so %s -o %s", + bjamout, base, + obj, so); + BOOST_TEST_CHECKPOINT("link: " << link); + system(link); + + BOOST_TEST_CHECKPOINT("load: " << so); + auto handle = loadlib(so); + + BOOST_TEST_CHECKPOINT("unload: " << handle); + closelib(handle); +} + +BOOST_AUTO_TEST_SUITE_END(); + diff --git a/slicer/test/run-slicer.cpp b/slicer/test/run-slicer.cpp deleted file mode 100644 index 8b56eed..0000000 --- a/slicer/test/run-slicer.cpp +++ /dev/null @@ -1,289 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "helpers.h" - -namespace fs = boost::filesystem; -#define SHORT(x) boost::numeric_cast< ::Ice::Short >(x) - -namespace Slicer { - boost::posix_time::ptime - dateTimeToPTime(const ::TestModule::DateTime &) - { - throw std::runtime_error("Not implemented"); - } - - ::TestModule::DateTime - ptimeToDateTime(const boost::posix_time::ptime &) - { - throw std::runtime_error("Not implemented"); - } - - std::string - dateTimeToString(const ::TestModule::DateTime & in) - { - char buf[BUFSIZ]; - struct tm tm({ in.second, in.minute, in.hour, in.day, in.month, in.year, 0, 0, 0 -#ifdef _BSD_SOURCE - , 0, 0 -#endif - }); - mktime(&tm); - auto len = strftime(buf, BUFSIZ, "%Y-%b-%d %H:%M:%S", &tm); - return std::string(buf, len); - } - - ::TestModule::DateTime - stringToDateTime(const std::string & in) - { - struct tm tm; - memset(&tm, 0, sizeof(struct tm)); - auto end = strptime(in.c_str(), "%Y-%b-%d %H:%M:%S", &tm); - if (!end || *end) { - throw std::runtime_error("Invalid date string: " + in); - } - return ::TestModule::DateTime({ - SHORT(tm.tm_year), SHORT(tm.tm_mon), SHORT(tm.tm_mday), - SHORT(tm.tm_hour), SHORT(tm.tm_min), SHORT(tm.tm_sec)}); - } -} - -template -void -verifyByFile(const fs::path & root, const fs::path & tmp, const fs::path & infile, const boost::function & check = NULL) -{ - const fs::path input = root / "initial" / infile; - const fs::path output = tmp / infile; - const fs::path outputJson = tmp / fs::change_extension(infile, "json"); - const fs::path outputXml = tmp / fs::change_extension(infile, "xml"); - - fprintf(stderr, "%s : Deserialize\n", input.string().c_str()); - IceInternal::Handle p = Slicer::Deserialize(input); - if (check) { - fprintf(stderr, "%s : Check1\n", input.string().c_str()); - check(*p); - } - fprintf(stderr, "%s : Serialize -> %s\n", input.string().c_str(), outputJson.string().c_str()); - Slicer::Serialize(p, outputJson); - fprintf(stderr, "%s : Serialize -> %s\n", input.string().c_str(), outputXml.string().c_str()); - Slicer::Serialize(p, outputXml); - if (check) { - fprintf(stderr, "%s : Check2\n", input.string().c_str()); - check(*p); - } - fprintf(stderr, "%s : OK\n", input.string().c_str()); - - system(stringbf("diff -w %s %s", input, output)); -} - -template -void -verifyByHelper(const fs::path & root, const fs::path & tmp, const fs::path & infile, - const boost::function & in, - const boost::function & out, - const boost::function & ifree, - const boost::function & check = NULL) -{ - const fs::path input = root / "initial" / infile; - const fs::path output = tmp / infile; - - fprintf(stderr, "%s : Read\n", input.string().c_str()); - Internal docRead = in(input); - - fprintf(stderr, "%s : Deserialize\n", input.string().c_str()); - IceInternal::Handle p = Slicer::Deserialize(docRead); - ifree(docRead); - if (check) { - fprintf(stderr, "%s : Check1\n", input.string().c_str()); - check(*p); - } - - fprintf(stderr, "%s : Serialize\n", input.string().c_str()); - Internal docWrite; - Slicer::Serialize(p, docWrite); - if (check) { - fprintf(stderr, "%s : Check2\n", input.string().c_str()); - check(*p); - } - - fprintf(stderr, "%s : Write\n", input.string().c_str()); - out(docWrite, output); - ifree(docWrite); - - fprintf(stderr, "%s : OK\n", input.string().c_str()); - - system(stringbf("diff -w %s %s", input, output)); -} - -void -checkBuiltIns_valuesCorrect(const TestModule::BuiltIns & bt) -{ - BOOST_ASSERT(bt.mbool); - BOOST_ASSERT(bt.mbyte == 4); - BOOST_ASSERT(bt.mshort == 40); - BOOST_ASSERT(bt.mint == 80); - BOOST_ASSERT(bt.mlong == 800); - BOOST_ASSERT(bt.mfloat == 3.125); - BOOST_ASSERT(bt.mdouble == 3.0625); - BOOST_ASSERT(bt.mstring == "Sample text"); -} - -void -checkInherits_types(const TestModule::InheritanceCont & i) -{ - BOOST_ASSERT(i.b); - BOOST_ASSERT(TestModule::D1Ptr::dynamicCast(i.b)); - BOOST_ASSERT(TestModule::D1Ptr::dynamicCast(i.b)->a == 1); - BOOST_ASSERT(TestModule::D1Ptr::dynamicCast(i.b)->b == 2); - BOOST_ASSERT(i.bs.size() == 3); - BOOST_ASSERT(i.bs[0]); - BOOST_ASSERT(TestModule::D2Ptr::dynamicCast(i.bs[0])); - BOOST_ASSERT(TestModule::D2Ptr::dynamicCast(i.bs[0])->a == 1); - BOOST_ASSERT(TestModule::D2Ptr::dynamicCast(i.bs[0])->c == 100); - BOOST_ASSERT(i.bs[1]); - BOOST_ASSERT(TestModule::D3Ptr::dynamicCast(i.bs[1])); - BOOST_ASSERT(TestModule::D3Ptr::dynamicCast(i.bs[1])->a == 2); - BOOST_ASSERT(TestModule::D3Ptr::dynamicCast(i.bs[1])->c == 100); - BOOST_ASSERT(TestModule::D3Ptr::dynamicCast(i.bs[1])->d == 200); - BOOST_ASSERT(i.bs[2]); - BOOST_ASSERT(i.bs[2]->a == 3); - BOOST_ASSERT(!TestModule::D1Ptr::dynamicCast(i.bs[2])); - BOOST_ASSERT(!TestModule::D2Ptr::dynamicCast(i.bs[2])); - BOOST_ASSERT(!TestModule::D3Ptr::dynamicCast(i.bs[2])); - BOOST_ASSERT(i.bm.size() == 3); - BOOST_ASSERT(TestModule::D1Ptr::dynamicCast(i.bm.find(10)->second)); - BOOST_ASSERT(TestModule::D3Ptr::dynamicCast(i.bm.find(12)->second)); - BOOST_ASSERT(!TestModule::D1Ptr::dynamicCast(i.bm.find(14)->second)); - BOOST_ASSERT(!TestModule::D2Ptr::dynamicCast(i.bm.find(14)->second)); - BOOST_ASSERT(!TestModule::D3Ptr::dynamicCast(i.bm.find(14)->second)); -} - -void -checkOptionals_notset(const TestModule::Optionals & opts) -{ - BOOST_ASSERT(!opts.optSimple); - BOOST_ASSERT(!opts.optStruct); - BOOST_ASSERT(!opts.optClass); - BOOST_ASSERT(!opts.optSeq); - BOOST_ASSERT(!opts.optDict); -} - -void -checkOptionals_areset(const TestModule::Optionals & opts) -{ - BOOST_ASSERT(opts.optSimple); - BOOST_ASSERT(opts.optSimple == 4); - BOOST_ASSERT(opts.optStruct); - BOOST_ASSERT(opts.optStruct->a == 1); - BOOST_ASSERT(opts.optStruct->b == 2); - BOOST_ASSERT(opts.optClass); - BOOST_ASSERT((*opts.optClass)->a == 1); - BOOST_ASSERT((*opts.optClass)->b == 2); - BOOST_ASSERT(opts.optSeq->size() == 2); - BOOST_ASSERT((*opts.optSeq)[0]->a == 3); - BOOST_ASSERT((*opts.optSeq)[0]->b == 4); - BOOST_ASSERT((*opts.optSeq)[1]->a == 5); - BOOST_ASSERT((*opts.optSeq)[1]->b == 6); - BOOST_ASSERT(opts.optDict); - BOOST_ASSERT(opts.optDict->size() == 2); - BOOST_ASSERT(opts.optDict->find(1) == opts.optDict->end()); - BOOST_ASSERT(opts.optDict->find(10) != opts.optDict->end()); - BOOST_ASSERT(opts.optDict->find(10)->second->a == 11); - BOOST_ASSERT(opts.optDict->find(10)->second->b == 12); - BOOST_ASSERT(opts.optDict->find(13) != opts.optDict->end()); - BOOST_ASSERT(opts.optDict->find(13)->second->a == 14); - BOOST_ASSERT(opts.optDict->find(13)->second->b == 15); -} - -xmlpp::Document * -readXml(const fs::path & path) -{ - return new xmlpp::Document(xmlParseFile(path.string().c_str())); -} - -void -writeXml(xmlpp::Document * const & doc, const fs::path & path) -{ - doc->write_to_file_formatted(path.string()); -} - -void -freeXml(xmlpp::Document * & doc) -{ - delete doc; -} - -json::Value -readJson(const fs::path & path) -{ - std::ifstream inFile(path.string()); - std::stringstream buffer; - buffer << inFile.rdbuf(); - Glib::ustring doc(buffer.str()); - Glib::ustring::const_iterator itr = doc.begin(); - return json::parseValue(itr); -} - -void -writeJson(const json::Value & value, const fs::path & path) -{ - std::ofstream outFile(path.string()); - json::serializeValue(value, outFile, "utf-8"); -} - -void -freeJson(json::Value &) -{ -} - -int -main(int, char ** argv) -{ - const fs::path me = argv[0]; - const fs::path base = "types"; - const fs::path bjamout = me.parent_path(); - const fs::path root = me.parent_path().parent_path().parent_path().parent_path(); - fprintf(stderr, "root -- %s\n", root.string().c_str()); - const fs::path slice = fs::change_extension(root / base, ".ice"); - fprintf(stderr, "slice - %s\n", slice.string().c_str()); - - // Tmp - const fs::path tmp = root / "bin" / "slicer"; - fprintf(stderr, "tmp --- %s\n", tmp.string().c_str()); - fs::create_directory(tmp); - const fs::path tmpf = tmp / "byFile"; - fs::create_directory(tmpf); - const fs::path tmph = tmp / "byHelper"; - fs::create_directory(tmph); - - // Execute - verifyByFile(root, tmpf, "builtins.xml", checkBuiltIns_valuesCorrect); - verifyByFile(root, tmpf, "optionals-notset.xml", checkOptionals_notset); - verifyByFile(root, tmpf, "optionals-areset.xml", checkOptionals_areset); - verifyByFile(root, tmpf, "inherit-a.xml"); - verifyByFile(root, tmpf, "inherit-b.xml", checkInherits_types); - verifyByFile(root, tmpf, "conv-datetime.xml"); - verifyByFile(root, tmpf, "builtins2.json", checkBuiltIns_valuesCorrect); - verifyByFile(root, tmpf, "optionals-areset2.json", checkOptionals_areset); - verifyByFile(root, tmpf, "inherit-c.json", checkInherits_types); - verifyByFile(root, tmpf, "inherit-d.json"); - verifyByFile(root, tmpf, "inherit-mapped.json"); - - verifyByHelper(root, tmph, "optionals-areset2.json", readJson, writeJson, freeJson, checkOptionals_areset); - verifyByHelper(root, tmph, "optionals-areset.xml", readXml, writeXml, freeXml, checkOptionals_areset); - - return 0; -} - diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp new file mode 100644 index 0000000..74ecf40 --- /dev/null +++ b/slicer/test/serializers.cpp @@ -0,0 +1,293 @@ +#define BOOST_TEST_MODULE execute_serializers +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "helpers.h" +#include "fileStructure.h" + +namespace fs = boost::filesystem; + +BOOST_TEST_DONT_PRINT_LOG_VALUE ( TestModule::ClassMap::const_iterator ) + +class FileBased : public FileStructure { + public: + template + void + verifyByFile(const fs::path & infile, const boost::function & check = NULL) + { + const fs::path input = root / "initial" / infile; + const fs::path output = tmp / infile; + const fs::path outputJson = tmp / fs::change_extension(infile, "json"); + const fs::path outputXml = tmp / fs::change_extension(infile, "xml"); + + BOOST_TEST_CHECKPOINT("Deserialize: " << input); + IceInternal::Handle p = Slicer::Deserialize(input); + + if (check) { + BOOST_TEST_CHECKPOINT("Check1: " << input); + check(*p); + } + + BOOST_TEST_CHECKPOINT("Serialize " << input << " -> " << outputJson); + Slicer::Serialize(p, outputJson); + + BOOST_TEST_CHECKPOINT("Serialize " << input << " -> " << outputXml); + Slicer::Serialize(p, outputXml); + + if (check) { + BOOST_TEST_CHECKPOINT("Check2: " << input); + check(*p); + } + + BOOST_TEST_CHECKPOINT("Checksum: " << input << " === " << output); + system(stringbf("diff -w %s %s", input, output)); + } + + template + void + verifyByHelper(const fs::path & infile, + const boost::function & in, + const boost::function & out, + const boost::function & ifree, + const boost::function & check = NULL) + { + const fs::path input = root / "initial" / infile; + const fs::path output = tmp / infile; + + BOOST_TEST_CHECKPOINT("Read: " << input); + Internal docRead = in(input); + + BOOST_TEST_CHECKPOINT("Deserialize: " << input); + IceInternal::Handle p = Slicer::Deserialize(docRead); + ifree(docRead); + + if (check) { + BOOST_TEST_CHECKPOINT("Check1: " << input); + check(*p); + } + + BOOST_TEST_CHECKPOINT("Serialize: " << input); + Internal docWrite; + Slicer::Serialize(p, docWrite); + + if (check) { + BOOST_TEST_CHECKPOINT("Check2: " << input); + check(*p); + } + + BOOST_TEST_CHECKPOINT("Write: " << output); + out(docWrite, output); + ifree(docWrite); + + BOOST_TEST_CHECKPOINT("Checksum: " << input << " === " << output); + system(stringbf("diff -w %s %s", input, output)); + } +}; + +void +checkBuiltIns_valuesCorrect(const TestModule::BuiltIns & bt) +{ + BOOST_REQUIRE_EQUAL(bt.mbool, true); + BOOST_REQUIRE_EQUAL(bt.mbyte, 4); + BOOST_REQUIRE_EQUAL(bt.mshort, 40); + BOOST_REQUIRE_EQUAL(bt.mint, 80); + BOOST_REQUIRE_EQUAL(bt.mlong, 800); + BOOST_REQUIRE_EQUAL(bt.mfloat, 3.125); + BOOST_REQUIRE_EQUAL(bt.mdouble, 3.0625); + BOOST_REQUIRE_EQUAL(bt.mstring, "Sample text"); +} + +void +checkInherits_types(const TestModule::InheritanceCont & i) +{ + BOOST_REQUIRE(i.b); + BOOST_REQUIRE(TestModule::D1Ptr::dynamicCast(i.b)); + BOOST_REQUIRE_EQUAL(TestModule::D1Ptr::dynamicCast(i.b)->a, 1); + BOOST_REQUIRE_EQUAL(TestModule::D1Ptr::dynamicCast(i.b)->b, 2); + BOOST_REQUIRE_EQUAL(i.bs.size(), 3); + BOOST_REQUIRE(i.bs[0]); + BOOST_REQUIRE(TestModule::D2Ptr::dynamicCast(i.bs[0])); + BOOST_REQUIRE_EQUAL(TestModule::D2Ptr::dynamicCast(i.bs[0])->a, 1); + BOOST_REQUIRE_EQUAL(TestModule::D2Ptr::dynamicCast(i.bs[0])->c, 100); + BOOST_REQUIRE(i.bs[1]); + BOOST_REQUIRE(TestModule::D3Ptr::dynamicCast(i.bs[1])); + BOOST_REQUIRE_EQUAL(TestModule::D3Ptr::dynamicCast(i.bs[1])->a, 2); + BOOST_REQUIRE_EQUAL(TestModule::D3Ptr::dynamicCast(i.bs[1])->c, 100); + BOOST_REQUIRE_EQUAL(TestModule::D3Ptr::dynamicCast(i.bs[1])->d, 200); + BOOST_REQUIRE(i.bs[2]); + BOOST_REQUIRE_EQUAL(i.bs[2]->a, 3); + BOOST_REQUIRE(!TestModule::D1Ptr::dynamicCast(i.bs[2])); + BOOST_REQUIRE(!TestModule::D2Ptr::dynamicCast(i.bs[2])); + BOOST_REQUIRE(!TestModule::D3Ptr::dynamicCast(i.bs[2])); + BOOST_REQUIRE_EQUAL(i.bm.size(), 3); + BOOST_REQUIRE(TestModule::D1Ptr::dynamicCast(i.bm.find(10)->second)); + BOOST_REQUIRE(TestModule::D3Ptr::dynamicCast(i.bm.find(12)->second)); + BOOST_REQUIRE(!TestModule::D1Ptr::dynamicCast(i.bm.find(14)->second)); + BOOST_REQUIRE(!TestModule::D2Ptr::dynamicCast(i.bm.find(14)->second)); + BOOST_REQUIRE(!TestModule::D3Ptr::dynamicCast(i.bm.find(14)->second)); +} + +void +checkOptionals_notset(const TestModule::Optionals & opts) +{ + BOOST_REQUIRE(!opts.optSimple); + BOOST_REQUIRE(!opts.optStruct); + BOOST_REQUIRE(!opts.optClass); + BOOST_REQUIRE(!opts.optSeq); + BOOST_REQUIRE(!opts.optDict); +} + +void +checkOptionals_areset(const TestModule::Optionals & opts) +{ + BOOST_REQUIRE(opts.optSimple); + BOOST_REQUIRE_EQUAL(opts.optSimple, 4); + BOOST_REQUIRE(opts.optStruct); + BOOST_REQUIRE_EQUAL(opts.optStruct->a, 1); + BOOST_REQUIRE_EQUAL(opts.optStruct->b, 2); + BOOST_REQUIRE(opts.optClass); + BOOST_REQUIRE_EQUAL((*opts.optClass)->a, 1); + BOOST_REQUIRE_EQUAL((*opts.optClass)->b, 2); + BOOST_REQUIRE_EQUAL(opts.optSeq->size(), 2); + BOOST_REQUIRE_EQUAL((*opts.optSeq)[0]->a, 3); + BOOST_REQUIRE_EQUAL((*opts.optSeq)[0]->b, 4); + BOOST_REQUIRE_EQUAL((*opts.optSeq)[1]->a, 5); + BOOST_REQUIRE_EQUAL((*opts.optSeq)[1]->b, 6); + BOOST_REQUIRE(opts.optDict); + BOOST_REQUIRE_EQUAL(opts.optDict->size(), 2); + BOOST_REQUIRE_EQUAL(opts.optDict->find(1), opts.optDict->end()); + BOOST_REQUIRE(opts.optDict->find(10) != opts.optDict->end()); + BOOST_REQUIRE_EQUAL(opts.optDict->find(10)->second->a, 11); + BOOST_REQUIRE_EQUAL(opts.optDict->find(10)->second->b, 12); + BOOST_REQUIRE(opts.optDict->find(13) != opts.optDict->end()); + BOOST_REQUIRE_EQUAL(opts.optDict->find(13)->second->a, 14); + BOOST_REQUIRE_EQUAL(opts.optDict->find(13)->second->b, 15); +} + +xmlpp::Document * +readXml(const fs::path & path) +{ + return new xmlpp::Document(xmlParseFile(path.string().c_str())); +} + +void +writeXml(xmlpp::Document * const & doc, const fs::path & path) +{ + doc->write_to_file_formatted(path.string()); +} + +void +freeXml(xmlpp::Document * & doc) +{ + delete doc; +} + +json::Value +readJson(const fs::path & path) +{ + std::ifstream inFile(path.string()); + std::stringstream buffer; + buffer << inFile.rdbuf(); + Glib::ustring doc(buffer.str()); + Glib::ustring::const_iterator itr = doc.begin(); + return json::parseValue(itr); +} + +void +writeJson(const json::Value & value, const fs::path & path) +{ + std::ofstream outFile(path.string()); + json::serializeValue(value, outFile, "utf-8"); +} + +void +freeJson(json::Value &) +{ +} + +BOOST_FIXTURE_TEST_SUITE ( byFile, FileBased ); + +BOOST_AUTO_TEST_CASE( builtins_xml ) +{ + verifyByFile("builtins.xml", checkBuiltIns_valuesCorrect); +} + +BOOST_AUTO_TEST_CASE( optionals_notset_xml ) +{ + verifyByFile("optionals-notset.xml", checkOptionals_notset); +} + +BOOST_AUTO_TEST_CASE( optionals_areset_xml ) +{ + verifyByFile("optionals-areset.xml", checkOptionals_areset); +} + +BOOST_AUTO_TEST_CASE( inherit_a_xml ) +{ + verifyByFile("inherit-a.xml"); +} + +BOOST_AUTO_TEST_CASE( inherit_b_xml ) +{ + verifyByFile("inherit-b.xml", checkInherits_types); +} + +BOOST_AUTO_TEST_CASE( conv_datetime_xml ) +{ + verifyByFile("conv-datetime.xml"); +} + +BOOST_AUTO_TEST_CASE( builtins2_json ) +{ + verifyByFile("builtins2.json", checkBuiltIns_valuesCorrect); +} + +BOOST_AUTO_TEST_CASE( optionals_areset2_json ) +{ + verifyByFile("optionals-areset2.json", checkOptionals_areset); +} + +BOOST_AUTO_TEST_CASE( inherit_c_json ) +{ + verifyByFile("inherit-c.json", checkInherits_types); +} + +BOOST_AUTO_TEST_CASE( inherit_d_json ) +{ + verifyByFile("inherit-d.json"); +} + +BOOST_AUTO_TEST_CASE( inherit_mapped_json ) +{ + verifyByFile("inherit-mapped.json"); +} + +BOOST_AUTO_TEST_SUITE_END(); + + +BOOST_FIXTURE_TEST_SUITE ( byHandler, FileBased ); + +BOOST_AUTO_TEST_CASE( optionals_areset2_json ) +{ + verifyByHelper("optionals-areset2.json", readJson, writeJson, freeJson, checkOptionals_areset); +} + +BOOST_AUTO_TEST_CASE( optionals_areset_xml ) +{ + verifyByHelper("optionals-areset.xml", readXml, writeXml, freeXml, checkOptionals_areset); +} + +BOOST_AUTO_TEST_SUITE_END(); + -- cgit v1.2.3