| 1 | |
| 2 | // SPDX-FileCopyrightText: (C) 2020 James Turner |
| 3 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 4 | |
| 5 | #include "testNasalLib.hxx" |
| 6 | |
| 7 | #include "test_suite/FGTestApi/testGlobals.hxx" |
| 8 | |
| 9 | #include <Main/globals.hxx> |
| 10 | #include <Main/util.hxx> |
| 11 | #include <Scripting/NasalSys.hxx> |
| 12 | |
| 13 | #include <Main/FGInterpolator.hxx> |
| 14 | |
| 15 | extern bool global_nasalMinimalInit; |
| 16 | |
| 17 | // Set up function for each test. |
| 18 | void NasalLibTests::setUp() |
| 19 | { |
| 20 | FGTestApi::setUp::initTestGlobals("NasalGC"); |
| 21 | |
| 22 | fgInitAllowedPaths(); |
| 23 | |
| 24 | globals->get_subsystem_mgr()->add<FGInterpolator>(); |
| 25 | |
| 26 | globals->get_subsystem_mgr()->bind(); |
| 27 | globals->get_subsystem_mgr()->init(); |
| 28 | |
| 29 | global_nasalMinimalInit = true; |
| 30 | globals->get_subsystem_mgr()->add<FGNasalSys>(); |
| 31 | |
| 32 | globals->get_subsystem_mgr()->postinit(); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | // Clean up after each test. |
| 37 | void NasalLibTests::tearDown() |
| 38 | { |
| 39 | global_nasalMinimalInit = false; |
| 40 | FGTestApi::tearDown::shutdownTestGlobals(); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | // Test test |
| 45 | void NasalLibTests::testVector() |
| 46 | { |
| 47 | bool ok = FGTestApi::executeNasal(R"( |
| 48 | |
| 49 | var v1 = ['apples', 'pears', 'lemons', 'strawberries']; |
| 50 | append(v1, 'melons'); |
| 51 | unitTest.assert_equal(size(v1), 5); |
| 52 | |
| 53 | var item = removeat(v1, 2); |
| 54 | unitTest.assert_equal(size(v1), 4); |
| 55 | unitTest.assert_equal(item,'lemons'); |
| 56 | unitTest.assert_equal(v1[2], 'strawberries'); |
| 57 | |
| 58 | remove(v1, 'carrots'); |
| 59 | unitTest.assert_equal(size(v1), 4); # nothing changes |
| 60 | |
| 61 | remove(v1, 'pears'); |
| 62 | unitTest.assert_equal(size(v1), 3); |
| 63 | unitTest.assert_equal(v1[2], 'melons'); |
| 64 | |
| 65 | unitTest.assert(contains(v1, 'pears') == 0); |
| 66 | |
| 67 | )"); |
| 68 | CPPUNIT_ASSERT(ok); |
| 69 | } |