From ec183829fbc40014bb3cb124bb46e4ca867682a7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 17 Jun 2018 15:25:04 +0100 Subject: 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. --- libadhocutil/compileTimeFormatter.h | 10 +++++----- libadhocutil/unittests/Jamfile.jam | 15 +++++++++++++++ libadhocutil/unittests/lorem-ipsum.txt | 9 +++++++++ libadhocutil/unittests/testCompileTimeFormatter.cpp | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 libadhocutil/unittests/lorem-ipsum.txt 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 class Formatter; + template class Formatter; template struct StreamWriter { @@ -93,7 +93,7 @@ namespace AdHoc { * Compile time string formatter. * @param S the format string. */ - template ()> + template ()> class Formatter { private: template friend struct StreamWriterBase; @@ -105,9 +105,9 @@ namespace AdHoc { * @return the formatted string. */ template - static inline std::string get(const Pn & ... pn) + static inline auto get(const Pn & ... pn) { - std::stringstream s; + std::basic_stringstream::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(); + constexpr auto ph = strchrnul(); 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 : : 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 boost_system boost_filesystem boost_utf + 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 #include +#include +#include #include @@ -266,3 +268,15 @@ BOOST_AUTO_TEST_CASE ( get ) BOOST_CHECK_EQUAL(s, "value something else"); } +constexpr +#include +BOOST_AUTO_TEST_CASE( lorem_ipsum ) +{ + typedef Formatter 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::type>(); + BOOST_CHECK_EQUAL_COLLECTIONS(s.begin(), s.end(), sv.begin(), sv.end()); +} + -- cgit v1.2.3