Path: blob/main/contrib/lutok/exceptions_test.cpp
102644 views
// Copyright 2011 Google Inc.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 "exceptions.hpp"2930#include <cstring>3132#include <atf-c++.hpp>3334#include "state.ipp"353637ATF_TEST_CASE_WITHOUT_HEAD(error);38ATF_TEST_CASE_BODY(error)39{40const lutok::error e("Some text");41ATF_REQUIRE(std::strcmp("Some text", e.what()) == 0);42}434445ATF_TEST_CASE_WITHOUT_HEAD(api_error__explicit);46ATF_TEST_CASE_BODY(api_error__explicit)47{48const lutok::api_error e("some_function", "Some text");49ATF_REQUIRE(std::strcmp("Some text", e.what()) == 0);50ATF_REQUIRE_EQ("some_function", e.api_function());51}525354ATF_TEST_CASE_WITHOUT_HEAD(api_error__from_stack);55ATF_TEST_CASE_BODY(api_error__from_stack)56{57lutok::state state;58state.push_integer(123);59state.push_string("The error message");60const lutok::api_error e = lutok::api_error::from_stack(state,61"the_function");62ATF_REQUIRE_EQ(1, state.get_top());63ATF_REQUIRE_EQ(123, state.to_integer(-1));64state.pop(1);65ATF_REQUIRE(std::strcmp("The error message", e.what()) == 0);66ATF_REQUIRE_EQ("the_function", e.api_function());67}686970ATF_TEST_CASE_WITHOUT_HEAD(file_not_found_error);71ATF_TEST_CASE_BODY(file_not_found_error)72{73const lutok::file_not_found_error e("missing-file");74ATF_REQUIRE(std::strcmp("File 'missing-file' not found", e.what()) == 0);75ATF_REQUIRE_EQ("missing-file", e.filename());76}777879ATF_INIT_TEST_CASES(tcs)80{81ATF_ADD_TEST_CASE(tcs, error);8283ATF_ADD_TEST_CASE(tcs, api_error__explicit);84ATF_ADD_TEST_CASE(tcs, api_error__from_stack);8586ATF_ADD_TEST_CASE(tcs, file_not_found_error);87}888990