SuspendVM.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // Copyright (c) 2012 Li-Cheng (Andy) Tai, atai@atai.org
  3. //
  4. // This software is provided 'as-is', without any express or implied
  5. // warranty. In no event will the authors be held liable for any damages
  6. // arising from the use of this software.
  7. //
  8. // Permission is granted to anyone to use this software for any purpose,
  9. // including commercial applications, and to alter it and redistribute it
  10. // freely, subject to the following restrictions:
  11. //
  12. // 1. The origin of this software must not be misrepresented; you must not
  13. // claim that you wrote the original software. If you use this software
  14. // in a product, an acknowledgment in the product documentation would be
  15. // appreciated but is not required.
  16. //
  17. // 2. Altered source versions must be plainly marked as such, and must not be
  18. // misrepresented as being the original software.
  19. //
  20. // 3. This notice may not be removed or altered from any source
  21. // distribution.
  22. //
  23. #include <gtest/gtest.h>
  24. #include <sqrat.h>
  25. #include "Fixture.h"
  26. /* test demonstrating Sourceforge bug 3507590 */
  27. using namespace Sqrat;
  28. class C
  29. {
  30. public:
  31. int suspend()
  32. {
  33. return sq_suspendvm(DefaultVM::Get());
  34. }
  35. };
  36. TEST_F(SqratTest, SuspendVM)
  37. {
  38. DefaultVM::Set(vm);
  39. int i;
  40. Class<C> cclass(vm, _SC("C"));
  41. cclass.Func(_SC("suspend"), &C::suspend);
  42. RootTable().Bind(_SC("C"), cclass);
  43. Script script;
  44. script.CompileString(_SC("\
  45. c <- C(); \
  46. //c.suspend(); /* this would fail in the curent Sqrat; no solution yet */\
  47. ::suspend(); \
  48. gTest.EXPECT_INT_EQ(1, 0); /* should not reach here */ \
  49. "));
  50. if (Sqrat::Error::Occurred(vm)) {
  51. FAIL() << _SC("Compile Failed: ") << Sqrat::Error::Message(vm);
  52. }
  53. script.Run();
  54. if (Sqrat::Error::Occurred(vm)) {
  55. FAIL() << _SC("Run Failed: ") << Sqrat::Error::Message(vm);
  56. }
  57. }