summaryrefslogtreecommitdiffhomepage
path: root/tests/test-environment.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2022-12-31 13:45:31 +0100
committerRoland Reichwein <mail@reichwein.it>2022-12-31 13:45:31 +0100
commit06a5b6fe71abac44286adf9c9f439ad5a2e3a519 (patch)
treefba06f886db2b116030e2316646ebc83245a94d3 /tests/test-environment.cpp
parent921c799f3aa0163cd2eeda5a1c3c8d10d5989e9c (diff)
Added tests
Diffstat (limited to 'tests/test-environment.cpp')
-rw-r--r--tests/test-environment.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test-environment.cpp b/tests/test-environment.cpp
new file mode 100644
index 0000000..da8e4e0
--- /dev/null
+++ b/tests/test-environment.cpp
@@ -0,0 +1,48 @@
+#include <boost/test/unit_test.hpp>
+#include <boost/test/data/dataset.hpp>
+#include <boost/test/data/monomorphic.hpp>
+#include <boost/test/data/test_case.hpp>
+
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/xml_parser.hpp>
+
+#include <sstream>
+#include <string>
+
+using namespace std::string_literals;
+namespace pt = boost::property_tree;
+
+// test ptree construction and xml serialization
+BOOST_AUTO_TEST_CASE(property_tree_put)
+{
+ pt::ptree p;
+ pt::ptree list;
+
+ pt::ptree entry;
+
+ entry.put_value("name1.txt");
+ entry.put("<xmlattr>.type", "file1");
+
+ list.push_back(pt::ptree::value_type("listentry", entry));
+
+ entry.put_value("name2.txt");
+ entry.put("<xmlattr>.type", "file2");
+
+ list.push_back(pt::ptree::value_type("listentry", entry));
+
+ p.push_back(pt::ptree::value_type("list", list));
+
+ std::stringstream ss;
+
+ pt::xml_parser::write_xml(ss, p /*, pt::xml_parser::xml_writer_make_settings<std::string>(' ', 1)*/);
+
+ BOOST_CHECK_EQUAL(ss.str(), "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<list><listentry type=\"file1\">name1.txt</listentry><listentry type=\"file2\">name2.txt</listentry></list>");
+}
+
+// test std::stoul for negative numbers
+BOOST_AUTO_TEST_CASE(string_stoul)
+{
+ unsigned long l = std::stoul("-1");
+
+ BOOST_CHECK_EQUAL(l, std::numeric_limits<unsigned long>::max());
+}