diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-06-17 15:25:04 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-06-17 15:32:16 +0100 |
commit | ec183829fbc40014bb3cb124bb46e4ca867682a7 (patch) | |
tree | 54beec6d8172c0af5fa2ba6566533990dc26b72a | |
parent | Simplify CTF invalid static_assert (diff) | |
download | libadhocutil-ec183829fbc40014bb3cb124bb46e4ca867682a7.tar.bz2 libadhocutil-ec183829fbc40014bb3cb124bb46e4ca867682a7.tar.xz libadhocutil-ec183829fbc40014bb3cb124bb46e4ca867682a7.zip |
Lorem Ipsum test
Adds test case when formatter content is generated from a simple .txt
file using xxd. The header is simply including and processed as a string
literal.
-rw-r--r-- | libadhocutil/compileTimeFormatter.h | 10 | ||||
-rw-r--r-- | libadhocutil/unittests/Jamfile.jam | 15 | ||||
-rw-r--r-- | libadhocutil/unittests/lorem-ipsum.txt | 9 | ||||
-rw-r--r-- | libadhocutil/unittests/testCompileTimeFormatter.cpp | 14 |
4 files changed, 43 insertions, 5 deletions
diff --git a/libadhocutil/compileTimeFormatter.h b/libadhocutil/compileTimeFormatter.h index d191ffc..4097ce5 100644 --- a/libadhocutil/compileTimeFormatter.h +++ b/libadhocutil/compileTimeFormatter.h @@ -34,7 +34,7 @@ namespace AdHoc { return off; } - template <const auto &, auto> class Formatter; + template <const auto &, int> class Formatter; template<const auto & S, auto L, auto pos, typename stream, auto ...> struct StreamWriter { @@ -93,7 +93,7 @@ namespace AdHoc { * Compile time string formatter. * @param S the format string. */ - template <const auto & S, auto L = strlen<S>()> + template <const auto & S, int L = strlen<S>()> class Formatter { private: template<const auto &, auto, auto, typename> friend struct StreamWriterBase; @@ -105,9 +105,9 @@ namespace AdHoc { * @return the formatted string. */ template<typename ... Pn> - static inline std::string get(const Pn & ... pn) + static inline auto get(const Pn & ... pn) { - std::stringstream s; + std::basic_stringstream<typename std::decay<decltype(*S)>::type> s; return write(s, pn...).str(); } @@ -130,7 +130,7 @@ namespace AdHoc { run(stream & s, const Pn & ... pn) { if (pos != L) { - constexpr auto ph = strchrnul<S, '%', pos>(); + constexpr auto ph = strchrnul<S, '%', pos, L>(); if constexpr (ph != pos) { s.write((S + pos), ph - pos); } diff --git a/libadhocutil/unittests/Jamfile.jam b/libadhocutil/unittests/Jamfile.jam index 95e9a82..dd0a80f 100644 --- a/libadhocutil/unittests/Jamfile.jam +++ b/libadhocutil/unittests/Jamfile.jam @@ -1,6 +1,18 @@ import testing ; +import type ; +import generators ; path-constant me : . ; +type.register TEXT : txt ; + +generators.register-standard xxd.h : TEXT : H ; + +actions xxd.h +{ + ( cd ./$(2:D) && xxd -i $(2:B).txt ) > $(1[1]) +} + +IMPORT $(__name__) : xxd.h : : xxd.h ; lib boost_utf : : <name>boost_unit_test_framework ; lib boost_filesystem ; @@ -9,6 +21,8 @@ lib boost_thread ; lib pthread ; lib dl ; +h lorem-ipsum : lorem-ipsum.txt ; + run testCompileTimeFormatter.cpp : : : @@ -18,6 +32,7 @@ run <library>boost_system <library>boost_filesystem <library>boost_utf + <implicit-dependency>lorem-ipsum ; run diff --git a/libadhocutil/unittests/lorem-ipsum.txt b/libadhocutil/unittests/lorem-ipsum.txt new file mode 100644 index 0000000..0f43c5b --- /dev/null +++ b/libadhocutil/unittests/lorem-ipsum.txt @@ -0,0 +1,9 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam erat dolor, volutpat eleifend varius a, sollicitudin tempor dui. Maecenas tortor ex, congue ac lobortis id, luctus eget metus. Proin laoreet metus ex, in tincidunt mauris vehicula non. Curabitur vitae tortor sagittis, efficitur risus non, ultrices est. Nam a sagittis elit. Ut condimentum urna sem, sed fringilla erat consequat at. Donec vehicula purus in magna lobortis luctus. Aenean dignissim elit sed sem posuere, non mattis leo mollis. Suspendisse malesuada facilisis tristique. Vestibulum a sem sed ex congue fringilla. Duis bibendum lorem eget dui bibendum varius. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. + +Nullam a turpis mollis, dignissim lacus eget, pretium orci. Cras maximus auctor quam eu feugiat. Nulla et odio sed felis vehicula consectetur. Suspendisse velit mauris, vehicula eget ante ut, luctus sagittis diam. Nullam id mattis libero. Nulla dolor ipsum, feugiat sit amet purus ac, aliquet fermentum sem. Maecenas volutpat est non bibendum dignissim. Pellentesque eleifend sem risus, a interdum quam scelerisque eu. + +Vivamus dignissim nisl id turpis finibus, volutpat ultrices tortor commodo. Cras nec nisi at eros sodales sollicitudin. Vestibulum in elementum turpis. Praesent in porta urna. Nunc placerat sed velit tristique sodales. Aenean dapibus dui eget risus venenatis, nec tristique augue porttitor. Nunc interdum magna non eros egestas gravida. + +Aliquam dictum diam a quam fermentum laoreet. Maecenas viverra neque nisi, eget elementum mauris luctus placerat. Donec vulputate, dui eget vestibulum congue, mauris ligula elementum nisi, eu placerat mi mi in lectus. Duis ut lacinia nunc. Aliquam erat volutpat. Suspendisse imperdiet rutrum ipsum ac mollis. In tristique, metus vel vehicula tristique, augue nibh finibus nisl, quis molestie quam est et nunc. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis dignissim lacus. Duis ac venenatis velit, in efficitur nulla. Mauris ut mollis nibh. Pellentesque ut nisi elementum, ullamcorper nisl sit amet, posuere tellus. Phasellus vestibulum volutpat finibus. Nunc feugiat ac ante et luctus. Donec id massa non urna fringilla laoreet id et erat. + +Suspendisse consectetur auctor metus, sit amet vulputate quam egestas ut. Curabitur odio nisi, condimentum varius malesuada tempus, eleifend sed eros. Vivamus nec est vitae libero sagittis euismod. Integer tincidunt a lacus eget ultricies. Duis nibh sapien, gravida ac congue ac, luctus et elit. Maecenas pretium lacus nibh, eu placerat nunc mollis eget. Donec volutpat quam in quam consequat, quis efficitur velit ultricies. Suspendisse placerat massa a nulla dictum tincidunt. Donec dictum malesuada feugiat. Vivamus tincidunt ut dolor eu porttitor. Proin sem justo, rutrum bibendum sagittis sit amet, rutrum vel lectus. Proin pellentesque molestie massa ac maximus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vestibulum consectetur urna ac turpis tincidunt consequat. Integer nec tellus et lorem tincidunt tristique. Curabitur quis purus at arcu feugiat malesuada non eu orci. diff --git a/libadhocutil/unittests/testCompileTimeFormatter.cpp b/libadhocutil/unittests/testCompileTimeFormatter.cpp index 59d63d0..9d01a80 100644 --- a/libadhocutil/unittests/testCompileTimeFormatter.cpp +++ b/libadhocutil/unittests/testCompileTimeFormatter.cpp @@ -2,6 +2,8 @@ #include <boost/test/unit_test.hpp> #include <compileTimeFormatter.h> +#include <fileUtils.h> +#include <definedDirs.h> #include <boost/filesystem/path.hpp> @@ -266,3 +268,15 @@ BOOST_AUTO_TEST_CASE ( get ) BOOST_CHECK_EQUAL(s, "value something else"); } +constexpr +#include <lorem-ipsum.h> +BOOST_AUTO_TEST_CASE( lorem_ipsum ) +{ + typedef Formatter<lorem_ipsum_txt, sizeof(lorem_ipsum_txt)> LIF; + auto s = LIF::get(); + BOOST_CHECK_EQUAL(s.length(), lorem_ipsum_txt_len); + AdHoc::FileUtils::MemMap li(rootDir / "lorem-ipsum.txt"); + auto sv = li.sv<std::decay<decltype(*lorem_ipsum_txt)>::type>(); + BOOST_CHECK_EQUAL_COLLECTIONS(s.begin(), s.end(), sv.begin(), sv.end()); +} + |