From 9cc019c4834cb1713f6b3bef149908c11f5e0759 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 18 Mar 2022 01:08:29 +0100 Subject: [PATCH] Test: Add example test --- test/test_hello_world.cc | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/test_hello_world.cc diff --git a/test/test_hello_world.cc b/test/test_hello_world.cc new file mode 100644 index 0000000..aa945c9 --- /dev/null +++ b/test/test_hello_world.cc @@ -0,0 +1,44 @@ +// This file is under GNU General Public License 3.0 +// see LICENSE.txt +#include "hello_world.hh" +#include + +// 2 Reasons why this 'using namespace' is okay +// 1. We cannot put main() in the namespace pEp, +// 2. If we were to extract parts of this file into a header-extension (hxx) as a template function/class +// we would be in the namespace pEp anyways. +using namespace pEp; + +int main() +{ + std::cout << "Test Hello World" << std::endl; + { + std::cout << "Test non-template func" << std::endl; + std::string ret = HelloWorld::hello_world(); + std::cout << ret << std::endl; + assert(ret == "hello world"); + } + + { + std::cout << "Test invoke generated template for std::string" << std::endl; + std::string ret = HelloWorld::hello_world("pEp"); + std::cout << ret << std::endl; + assert(ret == "pEp"); + } + + { + std::cout << "Test specialization for int" << std::endl; + int ret = HelloWorld::hello_world(404); + std::cout << ret << std::endl; + assert(ret == 808); + } + + { + std::cout << "Test specialization for double" << std::endl; + double ret = HelloWorld::hello_world(4.04); + std::cout << ret << std::endl; + assert(ret == 8.08); + } + std::cout << "All tests passed" << std::endl; + return 0; +}