#define CATCH_CONFIG_MAIN #include "catch.hpp" #include "../functions.hpp" #include TEST_CASE( "encodeUrl" ) { std::string url1 = "http://google.com"; std::string url1_expected = "http%3A%2F%2Fgoogle.com"; REQUIRE( encodeUrl( url1 ) == url1_expected ); std::string url2 = "https://www.google.com/search?q=日本語"; std::string url2_expected = "https%3A%2F%2Fwww.google.com%2Fsearch%3F" "q%3D%E6%97%A5%E6%9C%AC%E8%AA%9E"; REQUIRE( encodeUrl( url2 ) == url2_expected ); } TEST_CASE( "userHome" ) { SECTION( "correct usage" ) { auto home = userHome(); std::string command = "/bin/bash -c \"if [ \"${HOME}\" == \""; command += home; command += "\" ] ; then exit 0 ; else exit 1 ; fi\""; REQUIRE( system( command.c_str() ) == 0 ); } SECTION( "exception with non existing user" ) { setresgid( 1025, 1025, 1025 ); setresuid( 1025, 1025, 1025 ); REQUIRE_THROWS_WITH( userHome(), Catch::Matchers::Contains( "User with uid" ) && Catch::Matchers::Contains( "doesn't exist!" ) ); } }