Path: blob/main/contrib/kyua/utils/config/exceptions_test.cpp
48081 views
// Copyright 2012 The Kyua Authors.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions are5// met:6//7// * Redistributions of source code must retain the above copyright8// notice, this list of conditions and the following disclaimer.9// * Redistributions in binary form must reproduce the above copyright10// notice, this list of conditions and the following disclaimer in the11// documentation and/or other materials provided with the distribution.12// * Neither the name of Google Inc. nor the names of its contributors13// may be used to endorse or promote products derived from this software14// without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2728#include "utils/config/exceptions.hpp"2930#include <cstring>3132#include <atf-c++.hpp>3334#include "utils/config/tree.ipp"3536namespace config = utils::config;37namespace detail = utils::config::detail;383940ATF_TEST_CASE_WITHOUT_HEAD(error);41ATF_TEST_CASE_BODY(error)42{43const config::error e("Some text");44ATF_REQUIRE(std::strcmp("Some text", e.what()) == 0);45}464748ATF_TEST_CASE_WITHOUT_HEAD(bad_combination_error);49ATF_TEST_CASE_BODY(bad_combination_error)50{51detail::tree_key key;52key.push_back("first");53key.push_back("second");5455const config::bad_combination_error e(key, "Failed to combine '%s'");56ATF_REQUIRE(std::strcmp("Failed to combine 'first.second'", e.what()) == 0);57}585960ATF_TEST_CASE_WITHOUT_HEAD(invalid_key_error);61ATF_TEST_CASE_BODY(invalid_key_error)62{63const config::invalid_key_error e("Some text");64ATF_REQUIRE(std::strcmp("Some text", e.what()) == 0);65}666768ATF_TEST_CASE_WITHOUT_HEAD(invalid_key_value);69ATF_TEST_CASE_BODY(invalid_key_value)70{71detail::tree_key key;72key.push_back("1");73key.push_back("two");7475const config::invalid_key_value e(key, "foo bar");76ATF_REQUIRE(std::strcmp("Invalid value for property '1.two': foo bar",77e.what()) == 0);78}798081ATF_TEST_CASE_WITHOUT_HEAD(syntax_error);82ATF_TEST_CASE_BODY(syntax_error)83{84const config::syntax_error e("Some text");85ATF_REQUIRE(std::strcmp("Some text", e.what()) == 0);86}878889ATF_TEST_CASE_WITHOUT_HEAD(unknown_key_error__default_message);90ATF_TEST_CASE_BODY(unknown_key_error__default_message)91{92detail::tree_key key;93key.push_back("1");94key.push_back("two");9596const config::unknown_key_error e(key);97ATF_REQUIRE(std::strcmp("Unknown configuration property '1.two'",98e.what()) == 0);99}100101102ATF_TEST_CASE_WITHOUT_HEAD(unknown_key_error__custom_message);103ATF_TEST_CASE_BODY(unknown_key_error__custom_message)104{105detail::tree_key key;106key.push_back("1");107key.push_back("two");108109const config::unknown_key_error e(key, "The test '%s' string");110ATF_REQUIRE(std::strcmp("The test '1.two' string", e.what()) == 0);111}112113114ATF_TEST_CASE_WITHOUT_HEAD(value_error);115ATF_TEST_CASE_BODY(value_error)116{117const config::value_error e("Some text");118ATF_REQUIRE(std::strcmp("Some text", e.what()) == 0);119}120121122ATF_INIT_TEST_CASES(tcs)123{124ATF_ADD_TEST_CASE(tcs, error);125ATF_ADD_TEST_CASE(tcs, bad_combination_error);126ATF_ADD_TEST_CASE(tcs, invalid_key_error);127ATF_ADD_TEST_CASE(tcs, invalid_key_value);128ATF_ADD_TEST_CASE(tcs, syntax_error);129ATF_ADD_TEST_CASE(tcs, unknown_key_error__default_message);130ATF_ADD_TEST_CASE(tcs, unknown_key_error__custom_message);131ATF_ADD_TEST_CASE(tcs, value_error);132}133134135