diff options
-rw-r--r-- | slicer/db/Jamfile.jam | 3 | ||||
-rw-r--r-- | slicer/db/testInsert.cpp | 19 | ||||
-rw-r--r-- | slicer/db/testSelect.cpp | 5 | ||||
-rw-r--r-- | slicer/db/testUpdate.cpp | 7 | ||||
-rw-r--r-- | slicer/test/Jamfile.jam | 46 | ||||
-rw-r--r-- | slicer/test/classes.ice | 40 | ||||
-rw-r--r-- | slicer/test/collections.ice | 17 | ||||
-rw-r--r-- | slicer/test/conversions.cpp | 7 | ||||
-rw-r--r-- | slicer/test/db.ice | 34 | ||||
-rw-r--r-- | slicer/test/enums.ice | 15 | ||||
-rw-r--r-- | slicer/test/fileStructure.cpp | 21 | ||||
-rw-r--r-- | slicer/test/fileStructure.h | 25 | ||||
-rw-r--r-- | slicer/test/inheritance.ice | 44 | ||||
-rw-r--r-- | slicer/test/json.ice | 14 | ||||
-rw-r--r-- | slicer/test/optionals.ice | 19 | ||||
-rw-r--r-- | slicer/test/preprocessor.cpp | 84 | ||||
-rw-r--r-- | slicer/test/serializers.cpp | 38 | ||||
-rw-r--r-- | slicer/test/structs.ice | 34 | ||||
-rw-r--r-- | slicer/test/types.ice | 167 | ||||
-rw-r--r-- | slicer/test/xml.ice | 22 |
20 files changed, 366 insertions, 295 deletions
diff --git a/slicer/db/Jamfile.jam b/slicer/db/Jamfile.jam index c6915ef..54677a7 100644 --- a/slicer/db/Jamfile.jam +++ b/slicer/db/Jamfile.jam @@ -32,7 +32,6 @@ path-constant me : . ; run testSelect.cpp : : : - <define>ROOT=\"$(me)\" <define>BOOST_TEST_DYN_LINK <library>slicer-db <implicit-dependency>slicer-db @@ -53,7 +52,6 @@ run testSelect.cpp run testInsert.cpp : : : - <define>ROOT=\"$(me)\" <define>BOOST_TEST_DYN_LINK <library>slicer-db <library>dbpp-postgresql @@ -73,7 +71,6 @@ run testInsert.cpp run testUpdate.cpp : : : - <define>ROOT=\"$(me)\" <define>BOOST_TEST_DYN_LINK <library>slicer-db <implicit-dependency>slicer-db diff --git a/slicer/db/testInsert.cpp b/slicer/db/testInsert.cpp index ef37e66..34a236f 100644 --- a/slicer/db/testInsert.cpp +++ b/slicer/db/testInsert.cpp @@ -8,17 +8,18 @@ #include "sqlSelectDeserializer.h" #include <types.h> #include <common.h> +#include <db.h> // LCOV_EXCL_START BOOST_TEST_DONT_PRINT_LOG_VALUE(TestModule::DateTime); BOOST_TEST_DONT_PRINT_LOG_VALUE(TestModule::IsoDate); -BOOST_TEST_DONT_PRINT_LOG_VALUE(DB::Timespan); +BOOST_TEST_DONT_PRINT_LOG_VALUE(TestDatabase::Timespan); // LCOV_EXCL_STOP class StandardMockDatabase : public PQ::Mock { public: StandardMockDatabase() : PQ::Mock("user=postgres dbname=postgres", "pqmock", { - rootDir / "slicer.sql" }) + rootDir.parent_path() / "db" / "slicer.sql" }) { } }; @@ -117,13 +118,13 @@ BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtins ) BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtinsWithNulls ) { auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock")); - DB::BuiltInSeq bis = { - DB::BuiltInsPtr(new DB::BuiltIns(true, IceUtil::Optional<Ice::Byte>(), 17, 0, 129, 2.3, 4.5, "more text")), - DB::BuiltInsPtr(new DB::BuiltIns(true, 6, 18, 0, 130, 3.4, IceUtil::Optional<Ice::Double>(), "even more text")) + TestDatabase::BuiltInSeq bis = { + TestDatabase::BuiltInsPtr(new TestDatabase::BuiltIns(true, IceUtil::Optional<Ice::Byte>(), 17, 0, 129, 2.3, 4.5, "more text")), + TestDatabase::BuiltInsPtr(new TestDatabase::BuiltIns(true, 6, 18, 0, 130, 3.4, IceUtil::Optional<Ice::Double>(), "even more text")) }; Slicer::SerializeAny<Slicer::SqlFetchIdInsertSerializer>(bis, db.get(), "builtins"); auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM builtins WHERE mint IN (5, 6) ORDER BY mint")); - auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, DB::BuiltInSeq>(*sel); + auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(*sel); BOOST_REQUIRE_EQUAL(2, bis2.size()); BOOST_REQUIRE_EQUAL(bis.front()->mint, 5); BOOST_REQUIRE_EQUAL(bis.back()->mint, 6); @@ -141,14 +142,14 @@ BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtinsWithNulls ) BOOST_AUTO_TEST_CASE( insert_converted ) { auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock")); - DB::SpecificTypesPtr st = new DB::SpecificTypes { + TestDatabase::SpecificTypesPtr st = new TestDatabase::SpecificTypes { {2015, 10, 16, 19, 12, 34}, {2015, 10, 16}, - new DB::Timespan(1, 2, 3, 4) + new TestDatabase::Timespan(1, 2, 3, 4) }; Slicer::SerializeAny<Slicer::SqlInsertSerializer>(st, db.get(), "converted"); auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM converted")); - auto st2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, DB::SpecificTypesPtr>(*sel); + auto st2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::SpecificTypesPtr>(*sel); BOOST_REQUIRE_EQUAL(st->date, st2->date); BOOST_REQUIRE_EQUAL(st->dt, st2->dt); BOOST_REQUIRE_EQUAL(st->ts->days, st2->ts->days); diff --git a/slicer/db/testSelect.cpp b/slicer/db/testSelect.cpp index c1e2121..5428f29 100644 --- a/slicer/db/testSelect.cpp +++ b/slicer/db/testSelect.cpp @@ -7,12 +7,13 @@ #include "sqlSelectDeserializer.h" #include <types.h> #include <common.h> +#include <db.h> #include <sqlExceptions.h> class StandardMockDatabase : public PQ::Mock { public: StandardMockDatabase() : PQ::Mock("user=postgres dbname=postgres", "pqmock", { - rootDir / "slicer.sql" }) + rootDir.parent_path() / "db" / "slicer.sql" }) { } }; @@ -147,7 +148,7 @@ BOOST_AUTO_TEST_CASE( select_inherit_datetime ) "SELECT dt, to_char(dt, 'YYYY-MM-DD') date, ts \ FROM test \ WHERE id = 3")); - DB::SpecificTypesPtr bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, DB::SpecificTypesPtr>(*sel); + TestDatabase::SpecificTypesPtr bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::SpecificTypesPtr>(*sel); BOOST_REQUIRE_EQUAL(2015, bi->dt.year); BOOST_REQUIRE_EQUAL(3, bi->dt.month); BOOST_REQUIRE_EQUAL(27, bi->dt.day); diff --git a/slicer/db/testUpdate.cpp b/slicer/db/testUpdate.cpp index 1bf917e..624149d 100644 --- a/slicer/db/testUpdate.cpp +++ b/slicer/db/testUpdate.cpp @@ -9,12 +9,13 @@ #include "sqlUpdateSerializer.h" #include <types.h> #include <common.h> +#include <db.h> #include <sqlExceptions.h> class StandardMockDatabase : public PQ::Mock { public: StandardMockDatabase() : PQ::Mock("user=postgres dbname=postgres", "pqmock", { - rootDir / "slicer.sql" }) + rootDir.parent_path() / "db" / "slicer.sql" }) { } }; @@ -97,7 +98,7 @@ BOOST_AUTO_TEST_CASE( update_withNulls ) { auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock")); auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM builtins ORDER BY mint")); - auto bis = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, DB::BuiltInSeq>(*sel); + auto bis = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(*sel); BOOST_REQUIRE_EQUAL(2, bis.size()); BOOST_REQUIRE_EQUAL("string updated", *bis[0]->mstring); BOOST_REQUIRE_EQUAL("string", *bis[1]->mstring); @@ -109,7 +110,7 @@ BOOST_AUTO_TEST_CASE( update_withNulls ) bis[1]->mdouble = IceUtil::Optional<Ice::Double>(); BOOST_TEST_CHECKPOINT("Do update"); Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(bis, db.get(), "builtins"); - auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, DB::BuiltInSeq>(*sel); + auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(*sel); BOOST_REQUIRE(bis2[0]->mstring); BOOST_REQUIRE(!bis2[1]->mstring); BOOST_REQUIRE(bis2[0]->mbyte); diff --git a/slicer/test/Jamfile.jam b/slicer/test/Jamfile.jam index 7bf0b05..47240c3 100644 --- a/slicer/test/Jamfile.jam +++ b/slicer/test/Jamfile.jam @@ -27,56 +27,55 @@ actions slicer bind SLICERBIN "$(SLICERBIN)" -I"$(INCLUDES)" $(2) $(1[1]) $(ALLOWICE[1]) --headerPrefix="\"\"" } -cpp stypes : - types.ice +lib typesice : + [ glob *.ice ] : - <slicer>pure - <slicerbin>../tool//slicer - <dependency>../tool//slicer + <slicer>no + <include>. <include>included + <library>pthread + <library>Ice + <library>IceUtil + <library>included//included + <implicit-dependency>included//included + : : + <library>pthread + <library>Ice + <library>IceUtil ; lib types : - types.ice - stypes + [ glob *.ice ] conversions.cpp : + <dependency>../tool//slicer + <slicer>pure + <slicerbin>../tool//slicer <include>. - <library>pthread - <library>Ice - <library>IceUtil <library>adhocutil + <library>typesice <library>boost_date_time <library>included//included <library>../slicer//slicer + <implicit-dependency>typesice <implicit-dependency>included//included <implicit-dependency>../slicer//slicer : : <include>. - <library>pthread - <library>Ice - <library>IceUtil <library>included//included <library>../slicer//slicer + <library>typesice ; path-constant me : . ; -lib common : - helpers.cpp - fileStructure.cpp - : - <library>adhocutil - <library>boost_system - <library>boost_filesystem - <library>boost_utf - <define>ROOT=\"$(me)\" - : : +alias common : : : : <library>boost_filesystem <library>boost_system <define>BOOST_TEST_DYN_LINK <library>boost_utf <implicit-dependency>types + <define>ROOT=\"$(me)\" ; run preprocessor.cpp @@ -100,6 +99,7 @@ run compilation.cpp ; run serializers.cpp + helpers.cpp : : : <library>types <library>common diff --git a/slicer/test/classes.ice b/slicer/test/classes.ice new file mode 100644 index 0000000..c85f377 --- /dev/null +++ b/slicer/test/classes.ice @@ -0,0 +1,40 @@ +#ifndef SLICER_TEST_CLASSES +#define SLICER_TEST_CLASSES + +#include <structs.ice> + +module TestModule { + class DateTimeContainer { + [ "slicer:conversion:boost.posix_time.ptime:ptimeToDateTime:dateTimeToPTime", + "slicer:conversion:std.string:stringToDateTime:dateTimeToString:nodeclare" ] + DateTime dt; + IsoDate date; + }; + class BuiltIns { + bool mbool; + byte mbyte; + short mshort; + ["slicer:db:pkey", + "slicer:db:auto"] + int mint; + ["slicer:db:pkey"] + long mlong; + float mfloat; + double mdouble; + string mstring; + }; + [ "slicer:custommodelpart:TestModule.AbValidator" ] + class ClassType { + int a; + int b; + }; + class ClassClass { + ClassType cls; + StructType str; + ["slicer:xml:attribute"] + int simp; + }; +}; + +#endif + diff --git a/slicer/test/collections.ice b/slicer/test/collections.ice new file mode 100644 index 0000000..5ff54bd --- /dev/null +++ b/slicer/test/collections.ice @@ -0,0 +1,17 @@ +#ifndef SLICER_TEST_COLLECTIONS +#define SLICER_TEST_COLLECTIONS + +#include <classes.ice> +#include <structs.ice> + +module TestModule { + sequence<string> SimpleSeq; + sequence<BuiltIns> BuiltInSeq; + sequence<ClassType> Classes; + sequence<StructType> Structs; + dictionary<int, ClassType> ClassMap; + dictionary<int, StructType> StructMap; +}; + +#endif + diff --git a/slicer/test/conversions.cpp b/slicer/test/conversions.cpp index af3afcd..8510089 100644 --- a/slicer/test/conversions.cpp +++ b/slicer/test/conversions.cpp @@ -1,6 +1,7 @@ #include "conversions.h" #include <boost/numeric/conversion/cast.hpp> #include <visibility.h> +#include <db.h> #define SHORT(x) boost::numeric_cast< ::Ice::Short , int64_t >(x) @@ -90,15 +91,15 @@ namespace Slicer { } DLL_PUBLIC - ::DB::TimespanPtr + ::TestDatabase::TimespanPtr timedurationToTimespan(const boost::posix_time::time_duration & td) { - return new ::DB::Timespan(SHORT(td.hours() / 24), SHORT(td.hours() % 24), SHORT(td.minutes()), SHORT(td.seconds())); + return new ::TestDatabase::Timespan(SHORT(td.hours() / 24), SHORT(td.hours() % 24), SHORT(td.minutes()), SHORT(td.seconds())); } DLL_PUBLIC boost::posix_time::time_duration - timespanToTimeduration(const ::DB::TimespanPtr & ts) + timespanToTimeduration(const ::TestDatabase::TimespanPtr & ts) { return boost::posix_time::time_duration((ts->days * 24) + ts->hours, ts->minutes, ts->seconds); } diff --git a/slicer/test/db.ice b/slicer/test/db.ice new file mode 100644 index 0000000..a586503 --- /dev/null +++ b/slicer/test/db.ice @@ -0,0 +1,34 @@ +#ifndef SLICER_TEST_DB +#define SLICER_TEST_DB + +#include <classes.ice> + +module TestDatabase { + [ "slicer:conversion:boost.posix_time.time_duration:timedurationToTimespan:timespanToTimeduration" ] + class Timespan { + int days; + short hours; + short minutes; + short seconds; + }; + class SpecificTypes extends TestModule::DateTimeContainer { + Timespan ts; + }; + class BuiltIns { + optional(1) bool mbool; + optional(2) byte mbyte; + optional(3) short mshort; + ["slicer:db:pkey", + "slicer:db:auto"] + int mint; + ["slicer:db:pkey"] + long mlong; + optional(4) float mfloat; + optional(5) double mdouble; + optional(6) string mstring; + }; + sequence<BuiltIns> BuiltInSeq; +}; + +#endif + diff --git a/slicer/test/enums.ice b/slicer/test/enums.ice new file mode 100644 index 0000000..a482285 --- /dev/null +++ b/slicer/test/enums.ice @@ -0,0 +1,15 @@ +#ifndef SLICER_TEST_ENUMS +#define SLICER_TEST_ENUMS + +module TestModule { + enum SomeNumbers { + One = 1, Ten = 10, FiftyFive = 55 + }; + class SomeEnums { + SomeNumbers one; + SomeNumbers two; + }; +}; + +#endif + diff --git a/slicer/test/fileStructure.cpp b/slicer/test/fileStructure.cpp deleted file mode 100644 index 53b3c2d..0000000 --- a/slicer/test/fileStructure.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "fileStructure.h" -#include <boost/test/unit_test.hpp> -#include <boost/filesystem/convenience.hpp> -#include <definedDirs.h> - -FileStructure::FileStructure() : - me(selfExe), - base("types"), - bjamout("bin" / buildVariant), - root(rootDir), - included(root / "included"), - slice(fs::change_extension(root / base, ".ice")), - tmp(root / "bin" / "slicer") -{ - fs::create_directory(tmp); -} - -FileStructure::~FileStructure() -{ -} - diff --git a/slicer/test/fileStructure.h b/slicer/test/fileStructure.h deleted file mode 100644 index 4821fea..0000000 --- a/slicer/test/fileStructure.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SLICER_TEST_FILESTRUCTURE -#define SLICER_TEST_FILESTRUCTURE - -#include <boost/filesystem/path.hpp> -#include <visibility.h> - -namespace fs = boost::filesystem; - -class DLL_PUBLIC FileStructure { - public: - FileStructure(); - ~FileStructure(); - - protected: - const fs::path & me; - const fs::path base; - const fs::path bjamout; - const fs::path & root; - const fs::path included; - const fs::path slice; - const fs::path tmp; -}; - -#endif - diff --git a/slicer/test/inheritance.ice b/slicer/test/inheritance.ice new file mode 100644 index 0000000..3caa2eb --- /dev/null +++ b/slicer/test/inheritance.ice @@ -0,0 +1,44 @@ +#ifndef SLICER_TEST_INHERITANCE +#define SLICER_TEST_INHERITANCE + +module TestModule { + class Base { + int a; + }; + class D1 extends Base { + int b; + }; + class D2 extends Base { + int c; + }; + class D3 extends D2 { + int d; + }; + sequence<Base> BaseSeq; + dictionary<int, Base> BaseMap; + class InheritanceCont { + Base b; + BaseSeq bs; + BaseMap bm; + }; + ["slicer:typeid:mytype"] + class Base2 { + int a; + }; + class D12 extends Base2 { + int b; + }; + class InheritanceCont2 { + Base2 b; + }; + ["slicer:typename:onetwo"] + class D13 extends Base2 { + int c; + }; + class InheritanceContMapped { + Base2 b; + }; +}; + +#endif + diff --git a/slicer/test/json.ice b/slicer/test/json.ice new file mode 100644 index 0000000..8dfcc60 --- /dev/null +++ b/slicer/test/json.ice @@ -0,0 +1,14 @@ +#ifndef SLICER_TEST_JSON +#define SLICER_TEST_JSON + +module TestJson { + [ "slicer:json:object" ] + dictionary<string, int> Properties; + class HasProperities { + string name; + Properties props; + }; +}; + +#endif + diff --git a/slicer/test/optionals.ice b/slicer/test/optionals.ice new file mode 100644 index 0000000..63476ad --- /dev/null +++ b/slicer/test/optionals.ice @@ -0,0 +1,19 @@ +#ifndef SLICER_TEST_OPTIONALS +#define SLICER_TEST_OPTIONALS + +#include <classes.ice> +#include <structs.ice> +#include <collections.ice> + +module TestModule { + class Optionals { + optional(0) int optSimple; + optional(1) StructType optStruct; + optional(2) ClassType optClass; + optional(3) Classes optSeq; + optional(4) ClassMap optDict; + }; +}; + +#endif + diff --git a/slicer/test/preprocessor.cpp b/slicer/test/preprocessor.cpp index fadbac9..7431a2d 100644 --- a/slicer/test/preprocessor.cpp +++ b/slicer/test/preprocessor.cpp @@ -2,27 +2,69 @@ #include <boost/test/unit_test.hpp> #include <tool/parser.h> +#include <common.h> #include <boost/format.hpp> #include <buffer.h> +#include <definedDirs.h> #include "helpers.h" -#include "fileStructure.h" namespace fs = boost::filesystem; -const unsigned int COMPONENTS_IN_TEST_ICE = 40; +typedef std::map<std::string, unsigned int> ComponentsCount; +ComponentsCount COMPONENTS_IN_TEST_ICE = { + { "enums.ice", 2 }, + { "structs.ice", 4 }, + { "classes.ice", 4 }, + { "optionals.ice", 1 }, + { "collections.ice", 6 }, + { "inheritance.ice", 12 }, + { "interfaces.ice", 0 }, + { "json.ice", 2 }, + { "xml.ice", 2 }, + { "db.ice", 4 }, + { "types.ice", 3 } +}; -BOOST_FIXTURE_TEST_SUITE ( preprocessor, FileStructure ); +unsigned int +total() +{ + unsigned int t = 0; + for(const auto & c : COMPONENTS_IN_TEST_ICE) { + t += c.second; + } + return t; + BOOST_REQUIRE_EQUAL(40, t); +} + +void +process(Slicer::Slicer & s, const ComponentsCount::value_type & c) +{ +#if BOOST_VERSION / 100 >= 1060 + BOOST_TEST_CONTEXT(c.first) +#endif + { + s.slicePath = rootDir / c.first; + BOOST_REQUIRE_EQUAL(c.second, s.Execute()); + } +} + +void +processAll(Slicer::Slicer & s) +{ + s.includes.push_back(rootDir / "included"); + s.includes.push_back(rootDir); + for(const auto & c : COMPONENTS_IN_TEST_ICE) { + BOOST_TEST_CHECKPOINT(c.first); + process(s, c); + } + BOOST_REQUIRE_EQUAL(total(), s.Components()); +} BOOST_AUTO_TEST_CASE( slicer_test_counts_path ) { Slicer::Slicer s; - s.slicePath = slice; s.cppPath = "/dev/null"; - s.includes.push_back(included); - - auto count = s.Execute(); - BOOST_REQUIRE_EQUAL(COMPONENTS_IN_TEST_ICE, count); - BOOST_REQUIRE_EQUAL(COMPONENTS_IN_TEST_ICE, s.Components()); + processAll(s); } BOOST_AUTO_TEST_CASE( slicer_test_counts_filestar ) @@ -30,34 +72,14 @@ BOOST_AUTO_TEST_CASE( slicer_test_counts_filestar ) FILE * file = fopen("/dev/null", "a"); BOOST_REQUIRE(file); Slicer::Slicer s; - s.slicePath = slice; s.cpp = file; - s.includes.push_back(included); - - auto count = s.Execute(); - BOOST_REQUIRE_EQUAL(COMPONENTS_IN_TEST_ICE, count); - + processAll(s); fclose(file); } BOOST_AUTO_TEST_CASE( slicer_test_counts_nullfilestar ) { Slicer::Slicer s; - s.slicePath = slice; - s.includes.push_back(included); - - auto count = s.Execute(); - BOOST_REQUIRE_EQUAL(COMPONENTS_IN_TEST_ICE, count); + processAll(s); } -BOOST_AUTO_TEST_CASE( slicer_test_counts_interfacesOnly ) -{ - Slicer::Slicer s; - s.slicePath = root / "interfaces.ice"; - - auto count = s.Execute(); - BOOST_REQUIRE_EQUAL(0, count); -} - -BOOST_AUTO_TEST_SUITE_END(); - diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp index 65bc8cd..01c6688 100644 --- a/slicer/test/serializers.cpp +++ b/slicer/test/serializers.cpp @@ -13,9 +13,11 @@ #include <boost/format.hpp> #include <boost/function.hpp> #include <types.h> +#include <json.h> +#include <xml.h> #include <fstream> #include "helpers.h" -#include "fileStructure.h" +#include <definedDirs.h> #include "conversions.h" namespace fs = boost::filesystem; @@ -24,14 +26,14 @@ namespace fs = boost::filesystem; BOOST_TEST_DONT_PRINT_LOG_VALUE ( TestModule::ClassMap::iterator ) // LCOV_EXCL_STOP -class FileBased : public FileStructure { +class FileBased { public: template<typename T, typename DeserializerIn> void verifyByFile(const fs::path & infile, const boost::function<void(const T &)> & check = NULL) { - const fs::path input = root / "initial" / infile; - const fs::path tmpf = tmp / "byFile"; + const fs::path input = rootDir / "initial" / infile; + const fs::path tmpf = binDir / "byFile"; fs::create_directory(tmpf); const fs::path output = tmpf / infile; const fs::path outputJson = tmpf / fs::change_extension(infile, "json"); @@ -68,8 +70,8 @@ class FileBased : public FileStructure { const boost::function<void(Internal &)> & ifree, const boost::function<void(const T &)> & check = NULL) { - const fs::path input = root / "initial" / infile; - const fs::path tmph = tmp / "byHandler"; + const fs::path input = rootDir / "initial" / infile; + const fs::path tmph = binDir / "byHandler"; fs::create_directory(tmph); const fs::path output = tmph / infile; @@ -221,14 +223,14 @@ checkAssertEq(const T & expected, const T & actual) } void -checkEntityRef(const TestModule2::EntityRef & er) +checkEntityRef(const TestXml::EntityRef & er) { BOOST_REQUIRE_EQUAL(er.Id, 26); BOOST_REQUIRE_EQUAL(er.Name, "Hull City"); } void -checkBare(const TestModule::BareContainers & bc) +checkBare(const TestXml::BareContainers & bc) { BOOST_REQUIRE_EQUAL(bc.bareSeq.size(), 2); BOOST_REQUIRE_EQUAL(bc.bareSeq[0]->a, 1); @@ -347,7 +349,7 @@ BOOST_AUTO_TEST_CASE( simpleint_json ) BOOST_AUTO_TEST_CASE( complexClass_xmlattrAndText ) { - verifyByFile<TestModule2::EntityRef, Slicer::XmlFileDeserializer>("entityref.xml", checkEntityRef); + verifyByFile<TestXml::EntityRef, Slicer::XmlFileDeserializer>("entityref.xml", checkEntityRef); } BOOST_AUTO_TEST_CASE( sequenceOfClass_xml ) @@ -422,7 +424,7 @@ BOOST_AUTO_TEST_CASE( xml_attribute_xml ) BOOST_AUTO_TEST_CASE( xml_barecontainers_xml ) { - verifyByFile<TestModule::BareContainers, Slicer::XmlFileDeserializer>("bare.xml", checkBare); + verifyByFile<TestXml::BareContainers, Slicer::XmlFileDeserializer>("bare.xml", checkBare); } BOOST_AUTO_TEST_CASE( xml_classOfEnums_xml ) @@ -462,8 +464,8 @@ BOOST_AUTO_TEST_CASE( xml_simpleArray ) BOOST_AUTO_TEST_CASE( json_streams ) { - const auto tmpf = tmp / "byStream"; - const auto inFile = root / "initial" / "inherit-c.json"; + const auto tmpf = binDir / "byStream"; + const auto inFile = rootDir / "initial" / "inherit-c.json"; const auto outFile = tmpf / "streamout.json"; boost::filesystem::create_directories(tmpf); { @@ -478,8 +480,8 @@ BOOST_AUTO_TEST_CASE( json_streams ) BOOST_AUTO_TEST_CASE( xml_streams ) { - const auto tmpf = tmp / "byStream"; - const auto inFile = root / "initial" / "inherit-b.xml"; + const auto tmpf = binDir / "byStream"; + const auto inFile = rootDir / "initial" / "inherit-b.xml"; const auto outFile = tmpf / "streamout.xml"; boost::filesystem::create_directories(tmpf); { @@ -494,10 +496,10 @@ BOOST_AUTO_TEST_CASE( xml_streams ) BOOST_AUTO_TEST_CASE( invalid_enum ) { - Slicer::DeserializerPtr jdeserializer = new Slicer::JsonFileDeserializer(root / "initial" / "invalidEnum.json"); + Slicer::DeserializerPtr jdeserializer = new Slicer::JsonFileDeserializer(rootDir / "initial" / "invalidEnum.json"); BOOST_REQUIRE_THROW(Slicer::DeserializeAnyWith<TestModule::SomeNumbers>(jdeserializer), Slicer::InvalidEnumerationSymbol); - Slicer::DeserializerPtr xdeserializer = new Slicer::XmlFileDeserializer(root / "initial" / "invalidEnum.xml"); + Slicer::DeserializerPtr xdeserializer = new Slicer::XmlFileDeserializer(rootDir / "initial" / "invalidEnum.xml"); BOOST_REQUIRE_THROW(Slicer::DeserializeAnyWith<TestModule::SomeNumbers>(xdeserializer), Slicer::InvalidEnumerationSymbol); } @@ -552,11 +554,11 @@ BOOST_FIXTURE_TEST_SUITE ( compatWrapper, FileBased ); BOOST_AUTO_TEST_CASE( any ) { BOOST_TEST_CHECKPOINT("Create folders"); - const fs::path tmpf = tmp / "compatWrapper"; + const fs::path tmpf = binDir / "compatWrapper"; fs::create_directory(tmpf); BOOST_TEST_CHECKPOINT("Figure out paths"); - const boost::filesystem::path input = root / "initial" / "builtins.xml"; + const boost::filesystem::path input = rootDir / "initial" / "builtins.xml"; const boost::filesystem::path output = tmpf / "builtins.xml"; BOOST_TEST_CHECKPOINT("Deserialize with wrapper"); diff --git a/slicer/test/structs.ice b/slicer/test/structs.ice new file mode 100644 index 0000000..e06f93b --- /dev/null +++ b/slicer/test/structs.ice @@ -0,0 +1,34 @@ +#ifndef SLICER_TEST_STRUCTS +#define SLICER_TEST_STRUCTS + +["slicer:include:conversions.h"] +module TestModule { + struct DateTime { + short year; + short month; + short day; + short hour; + short minute; + short second; + }; + [ "slicer:conversion:std.string:stringToIsoDate:isoDateToString" ] + struct IsoDate { + short year; + [ "slicer:custommodelpart:TestModule.MonthValidator" ] + short month; + short day; + }; + struct StructType { + int a; + int b; + }; + class ClassType; + struct StructStruct { + ClassType cls; + StructType str; + int simp; + }; +}; + +#endif + diff --git a/slicer/test/types.ice b/slicer/test/types.ice index bdc8da8..a48f380 100644 --- a/slicer/test/types.ice +++ b/slicer/test/types.ice @@ -1,140 +1,24 @@ +#ifndef SLICER_TEST_TYPES +#define SLICER_TEST_TYPES + [["cpp:include:boost/date_time/posix_time/posix_time_types.hpp"]] [["cpp:include:boost/date_time/posix_time/time_formatters.hpp"]] [["cpp:include:boost/date_time/posix_time/time_parsers.hpp"]] #include <included.ice> +#include <enums.ice> +#include <structs.ice> +#include <classes.ice> +#include <collections.ice> +#include <optionals.ice> +#include <inheritance.ice> ["slicer:include:conversions.h"] module TestModule { - enum SomeNumbers { - One = 1, Ten = 10, FiftyFive = 55 - }; - struct DateTime { - short year; - short month; - short day; - short hour; - short minute; - short second; - }; - [ "slicer:conversion:std.string:stringToIsoDate:isoDateToString" ] - struct IsoDate { - short year; - [ "slicer:custommodelpart:TestModule.MonthValidator" ] - short month; - short day; - }; - class DateTimeContainer { - [ "slicer:conversion:boost.posix_time.ptime:ptimeToDateTime:dateTimeToPTime", - "slicer:conversion:std.string:stringToDateTime:dateTimeToString:nodeclare" ] - DateTime dt; - IsoDate date; - }; - class BuiltIns { - bool mbool; - byte mbyte; - short mshort; - ["slicer:db:pkey", - "slicer:db:auto"] - int mint; - ["slicer:db:pkey"] - long mlong; - float mfloat; - double mdouble; - string mstring; - }; - [ "slicer:custommodelpart:TestModule.AbValidator" ] - class ClassType { - int a; - int b; - }; - struct StructType { - int a; - int b; - }; - sequence<string> SimpleSeq; - sequence<BuiltIns> BuiltInSeq; - sequence<ClassType> Classes; - sequence<StructType> Structs; - dictionary<int, ClassType> ClassMap; - dictionary<int, StructType> StructMap; - class Optionals { - optional(0) int optSimple; - optional(1) StructType optStruct; - optional(2) ClassType optClass; - optional(3) Classes optSeq; - optional(4) ClassMap optDict; - }; - class ClassClass { - ClassType cls; - StructType str; - ["slicer:xml:attribute"] - int simp; - }; - struct StructStruct { - ClassType cls; - StructType str; - int simp; - }; - class Base { - int a; - }; - class D1 extends Base { - int b; - }; - class D2 extends Base { - int c; - }; - class D3 extends D2 { - int d; - }; - sequence<Base> BaseSeq; - dictionary<int, Base> BaseMap; - class InheritanceCont { - Base b; - BaseSeq bs; - BaseMap bm; - }; interface IgnoreMe { int someFunction(); DontCountMe otherFileReference(); }; - ["slicer:typeid:mytype"] - class Base2 { - int a; - }; - class D12 extends Base2 { - int b; - }; - class InheritanceCont2 { - Base2 b; - }; - ["slicer:typename:onetwo"] - class D13 extends Base2 { - int c; - }; - class InheritanceContMapped { - Base2 b; - }; - struct BareContainers { - [ "slicer:xml:bare" ] - Classes bareSeq; - [ "slicer:xml:bare" ] - ClassMap bareMap; - }; - class SomeEnums { - SomeNumbers one; - SomeNumbers two; - }; -}; - -module TestJson { - [ "slicer:json:object" ] - dictionary<string, int> Properties; - class HasProperities { - string name; - Properties props; - }; }; module TestModule2 { @@ -145,12 +29,6 @@ module TestModule2 { TestModule::DateTime dt; TestModule::Base base; }; - struct EntityRef { - [ "slicer:xml:attribute" ] - int Id; - [ "slicer:xml:text" ] - string Name; - }; class Conv { [ "slicer:conversion:boost.posix_time.ptime:boost.posix_time.to_iso_extended_string:boost.posix_time.time_from_string:nodeclare" ] string conv; @@ -162,30 +40,5 @@ module TestModule2 { }; }; -module DB { - [ "slicer:conversion:boost.posix_time.time_duration:timedurationToTimespan:timespanToTimeduration" ] - class Timespan { - int days; - short hours; - short minutes; - short seconds; - }; - class SpecificTypes extends TestModule::DateTimeContainer { - Timespan ts; - }; - class BuiltIns { - optional(1) bool mbool; - optional(2) byte mbyte; - optional(3) short mshort; - ["slicer:db:pkey", - "slicer:db:auto"] - int mint; - ["slicer:db:pkey"] - long mlong; - optional(4) float mfloat; - optional(5) double mdouble; - optional(6) string mstring; - }; - sequence<BuiltIns> BuiltInSeq; -}; +#endif diff --git a/slicer/test/xml.ice b/slicer/test/xml.ice new file mode 100644 index 0000000..ecb50b5 --- /dev/null +++ b/slicer/test/xml.ice @@ -0,0 +1,22 @@ +#ifndef SLICER_TEST_XML +#define SLICER_TEST_XML + +#include <collections.ice> + +module TestXml { + struct BareContainers { + [ "slicer:xml:bare" ] + TestModule::Classes bareSeq; + [ "slicer:xml:bare" ] + TestModule::ClassMap bareMap; + }; + struct EntityRef { + [ "slicer:xml:attribute" ] + int Id; + [ "slicer:xml:text" ] + string Name; + }; +}; + +#endif + |