Path: blob/main/contrib/lutok/stack_cleaner_test.cpp
102969 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 "stack_cleaner.hpp"2930#include <atf-c++.hpp>313233ATF_TEST_CASE_WITHOUT_HEAD(empty);34ATF_TEST_CASE_BODY(empty)35{36lutok::state state;37{38lutok::stack_cleaner cleaner(state);39ATF_REQUIRE_EQ(0, state.get_top());40}41ATF_REQUIRE_EQ(0, state.get_top());42}434445ATF_TEST_CASE_WITHOUT_HEAD(some);46ATF_TEST_CASE_BODY(some)47{48lutok::state state;49{50lutok::stack_cleaner cleaner(state);51state.push_integer(15);52ATF_REQUIRE_EQ(1, state.get_top());53state.push_integer(30);54ATF_REQUIRE_EQ(2, state.get_top());55}56ATF_REQUIRE_EQ(0, state.get_top());57}585960ATF_TEST_CASE_WITHOUT_HEAD(nested);61ATF_TEST_CASE_BODY(nested)62{63lutok::state state;64{65lutok::stack_cleaner cleaner1(state);66state.push_integer(10);67ATF_REQUIRE_EQ(1, state.get_top());68ATF_REQUIRE_EQ(10, state.to_integer(-1));69{70lutok::stack_cleaner cleaner2(state);71state.push_integer(20);72ATF_REQUIRE_EQ(2, state.get_top());73ATF_REQUIRE_EQ(20, state.to_integer(-1));74ATF_REQUIRE_EQ(10, state.to_integer(-2));75}76ATF_REQUIRE_EQ(1, state.get_top());77ATF_REQUIRE_EQ(10, state.to_integer(-1));78}79ATF_REQUIRE_EQ(0, state.get_top());80}818283ATF_TEST_CASE_WITHOUT_HEAD(forget);84ATF_TEST_CASE_BODY(forget)85{86lutok::state state;87{88lutok::stack_cleaner cleaner(state);89state.push_integer(15);90state.push_integer(30);91cleaner.forget();92state.push_integer(60);93ATF_REQUIRE_EQ(3, state.get_top());94}95ATF_REQUIRE_EQ(2, state.get_top());96ATF_REQUIRE_EQ(30, state.to_integer(-1));97state.pop(2);98}99100101ATF_INIT_TEST_CASES(tcs)102{103ATF_ADD_TEST_CASE(tcs, empty);104ATF_ADD_TEST_CASE(tcs, some);105ATF_ADD_TEST_CASE(tcs, nested);106ATF_ADD_TEST_CASE(tcs, forget);107}108109110