Debian Codegraph @

test_suite/unit_tests/general/test_Views.cxx

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 James Turner
3 *
4 * This file is part of the program FlightGear.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "test_Views.hxx"
21
22 #include <cstring>
23 #include <memory>
24
25 #include "test_suite/FGTestApi/NavDataCache.hxx"
26 #include "test_suite/FGTestApi/testGlobals.hxx"
27
28 #include <simgear/props/props_io.hxx>
29
30 #include <Main/fg_props.hxx>
31 #include <Main/globals.hxx>
32 #include <Viewer/view.hxx>
33 #include <Viewer/viewmgr.hxx>
34
35 /////////////////////////////////////////////////////////////////////////////
36
37 // Set up function for each test.
38 void ViewsTests::setUp()
39 {
40 FGTestApi::setUp::initTestGlobals("Views");
41 FGTestApi::setUp::initNavDataCache();
42 }
43
44 // Clean up after each test.
45 void ViewsTests::tearDown()
46 {
47 FGTestApi::tearDown::shutdownTestGlobals();
48 }
49
50 void ViewsTests::testBasic()
51 {
52 auto vm = globals->get_subsystem_mgr()->add<FGViewMgr>();
53
54 CPPUNIT_ASSERT_EQUAL(static_cast<flightgear::View*>(nullptr), vm->get_current_view());
55
56 // define simple views setup
57 const char* propsXML = R"(<?xml version="1.0" encoding="UTF-8"?>
58 <PropertyList>
59 <sim>
60 <view>
61 <name type="string">AView</name>
62 <internal type="bool">1</internal>
63 <type type="string">lookat</type>
64 <config>
65 </config>
66 </view>
67
68 <view>
69 <name type="string">BView</name>
70 <internal type="bool">0</internal>
71 <type type="string">lookfrom</type>
72 <config>
73 </config>
74 </view>
75 </sim>
76 </PropertyList>
77 )";
78
79 SGPropertyNode_ptr views = globals->get_props();
80 {
81 std::istringstream is(propsXML);
82 readProperties(is, views);
83 }
84
85 fgSetInt("/sim/current-view/view-number", 0);
86
87 globals->get_subsystem_mgr()->bind();
88 globals->get_subsystem_mgr()->init();
89 globals->get_subsystem_mgr()->postinit();
90
91 auto c = vm->get_current_view();
92 CPPUNIT_ASSERT(c);
93 CPPUNIT_ASSERT_EQUAL(true, c->getInternal());
94 CPPUNIT_ASSERT_EQUAL(std::string{"AView"}, c->getName());
95 CPPUNIT_ASSERT_EQUAL(flightgear::View::FG_LOOKAT, c->getType());
96
97 fgSetInt("/sim/current-view/view-number", 1);
98 CPPUNIT_ASSERT_EQUAL(1, vm->getCurrentViewIndex());
99
100 c = vm->get_current_view();
101 CPPUNIT_ASSERT_EQUAL(false, c->getInternal());
102 CPPUNIT_ASSERT_EQUAL(std::string{"BView"}, c->getName());
103 CPPUNIT_ASSERT_EQUAL(flightgear::View::FG_LOOKFROM, c->getType());
104
105 // disabled by James, since this asserts inside FGViewMgr::setCurrentViewIndex
106 #if 0
107 fgSetInt("/sim/current-view/view-number", 3);
108 CPPUNIT_ASSERT_EQUAL(0, vm->getCurrentViewIndex());
109 CPPUNIT_ASSERT_EQUAL(0, fgGetInt("/sim/current-view/view-number"));
110 #endif
111 }