Maintenance: namespace
Clean up namespaces. Don't use broad 'using namespace' context in header files. Header Guards. SPDX tags.
This commit is contained in:
parent
060ac34e19
commit
b2c3795f11
3 changed files with 33 additions and 57 deletions
|
@ -1,22 +1,9 @@
|
||||||
// NasalFlightPlan.cxx -- expose FlightPlan classes to Nasal
|
/*
|
||||||
//
|
* SPDX-FileName: NasalFlightPlan.cxx
|
||||||
// Written by James Turner, started 2020.
|
* SPDX-FileComment: expose FlightPlan classes to Nasal
|
||||||
//
|
* SPDX-FileCopyrightText: Copyright (C) 2020 James Turner
|
||||||
// Copyright (C) 2020 James Turner
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
//
|
*/
|
||||||
// This program is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation; either version 2 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful, but
|
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
@ -812,7 +799,7 @@ static void flightplanGhostSetMember(naContext c, void* g, naRef field, naRef va
|
||||||
}
|
}
|
||||||
|
|
||||||
if (naIsNil(value)) {
|
if (naIsNil(value)) {
|
||||||
fp->setSID(fp->sid(), string{});
|
fp->setSID(fp->sid(), std::string{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -882,7 +869,7 @@ static void flightplanGhostSetMember(naContext c, void* g, naRef field, naRef va
|
||||||
}
|
}
|
||||||
|
|
||||||
if (naIsNil(value)) {
|
if (naIsNil(value)) {
|
||||||
fp->setSTAR(fp->star(), string{});
|
fp->setSTAR(fp->star(), std::string{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -947,7 +934,7 @@ static void flightplanGhostSetMember(naContext c, void* g, naRef field, naRef va
|
||||||
}
|
}
|
||||||
|
|
||||||
if (naIsNil(value)) {
|
if (naIsNil(value)) {
|
||||||
fp->setApproach(fp->approach(), string{});
|
fp->setApproach(fp->approach(), std::string{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2175,7 +2162,7 @@ static naRef f_procedure_transition(naContext c, naRef me, int argc, naRef* args
|
||||||
naRuntimeError(c, "procedure.transition called on non-procedure object");
|
naRuntimeError(c, "procedure.transition called on non-procedure object");
|
||||||
}
|
}
|
||||||
|
|
||||||
const string ident{naStr_data(args[0])};
|
const std::string ident{naStr_data(args[0])};
|
||||||
const auto ty = proc->type();
|
const auto ty = proc->type();
|
||||||
if (Approach::isApproach(ty)) {
|
if (Approach::isApproach(ty)) {
|
||||||
const auto app = static_cast<Approach*>(proc);
|
const auto app = static_cast<Approach*>(proc);
|
||||||
|
|
|
@ -113,7 +113,7 @@ void FGNasalModelData::load()
|
||||||
|
|
||||||
SG_LOG(SG_NASAL, SG_DEBUG, "Loading nasal module " << _module.c_str());
|
SG_LOG(SG_NASAL, SG_DEBUG, "Loading nasal module " << _module.c_str());
|
||||||
|
|
||||||
const string s = _load ? _load->getStringValue() : "";
|
const std::string s = _load ? _load->getStringValue() : "";
|
||||||
auto nasalSys = globals->get_subsystem<FGNasalSys>();
|
auto nasalSys = globals->get_subsystem<FGNasalSys>();
|
||||||
|
|
||||||
// Add _module_id to script local hash to allow placing canvasses on objects
|
// Add _module_id to script local hash to allow placing canvasses on objects
|
||||||
|
@ -149,7 +149,7 @@ void FGNasalModelData::unload()
|
||||||
|
|
||||||
if (_unload)
|
if (_unload)
|
||||||
{
|
{
|
||||||
const string s = _unload->getStringValue();
|
const std::string s = _unload->getStringValue();
|
||||||
nasalSys->createModule(_module.c_str(), _module.c_str(), s.c_str(), s.length(), _root);
|
nasalSys->createModule(_module.c_str(), _module.c_str(), s.c_str(), s.length(), _root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,29 +1,18 @@
|
||||||
// Unit-test API for nasal
|
/*
|
||||||
//
|
* SPDX-FileName: NasalUnittesting.cxx
|
||||||
|
* SPDX-FileComment: Unit-test API for nasal
|
||||||
|
* SPDX-FileCopyrightText: Copyright (C) 2020 James Turner
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
// There are two versions of this module, and we load one or the other
|
// There are two versions of this module, and we load one or the other
|
||||||
// depending on if we're running the test_suite (using CppUnit) or
|
// depending on if we're running the test_suite (using CppUnit) or
|
||||||
// the normal simulator. The logic is that aircraft-developers and
|
// the normal simulator. The logic is that aircraft-developers and
|
||||||
// people hacking Nasal likely don't have a way to run the test-suite,
|
// people hacking Nasal likely don't have a way to run the test-suite,
|
||||||
// whereas core-developers and Jenksin want a way to run all tests
|
// whereas core-developers and Jenkins want a way to run all tests
|
||||||
// through the standard CppUnit mechanim. So we have a consistent
|
// through the standard CppUnit mechanism. So we have a consistent
|
||||||
// Nasal API, but different implement in fgfs_test_suite vs
|
// Nasal API, but different implement in fgfs_test_suite vs
|
||||||
// normal fgfs executable.
|
// normal fgfs executable.
|
||||||
//
|
|
||||||
// Copyright (C) 2020 James Turner
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation; either version 2 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful, but
|
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
@ -58,7 +47,7 @@ static std::unique_ptr<ActiveTest> static_activeTest;
|
||||||
static naRef f_assert(const nasal::CallContext& ctx )
|
static naRef f_assert(const nasal::CallContext& ctx )
|
||||||
{
|
{
|
||||||
bool pass = ctx.requireArg<bool>(0);
|
bool pass = ctx.requireArg<bool>(0);
|
||||||
auto msg = ctx.getArg<string>(1);
|
auto msg = ctx.getArg<std::string>(1);
|
||||||
|
|
||||||
if (!pass) {
|
if (!pass) {
|
||||||
if (!static_activeTest) {
|
if (!static_activeTest) {
|
||||||
|
@ -71,7 +60,7 @@ static naRef f_assert(const nasal::CallContext& ctx )
|
||||||
|
|
||||||
static_activeTest->failure = true;
|
static_activeTest->failure = true;
|
||||||
static_activeTest->failureMessage = msg;
|
static_activeTest->failureMessage = msg;
|
||||||
static_activeTest->failureFileName = ctx.from_nasal<string>(naGetSourceFile(ctx.c_ctx(), 0));
|
static_activeTest->failureFileName = ctx.from_nasal<std::string>(naGetSourceFile(ctx.c_ctx(), 0));
|
||||||
static_activeTest->failLineNumber = naGetLine(ctx.c_ctx(), 0);
|
static_activeTest->failLineNumber = naGetLine(ctx.c_ctx(), 0);
|
||||||
|
|
||||||
ctx.runtimeError("Test assert failed");
|
ctx.runtimeError("Test assert failed");
|
||||||
|
@ -82,7 +71,7 @@ static naRef f_assert(const nasal::CallContext& ctx )
|
||||||
|
|
||||||
static naRef f_fail(const nasal::CallContext& ctx )
|
static naRef f_fail(const nasal::CallContext& ctx )
|
||||||
{
|
{
|
||||||
auto msg = ctx.getArg<string>(0);
|
auto msg = ctx.getArg<std::string>(0);
|
||||||
|
|
||||||
if (!static_activeTest) {
|
if (!static_activeTest) {
|
||||||
ctx.runtimeError("No active test in progress");
|
ctx.runtimeError("No active test in progress");
|
||||||
|
@ -94,7 +83,7 @@ static naRef f_fail(const nasal::CallContext& ctx )
|
||||||
|
|
||||||
static_activeTest->failure = true;
|
static_activeTest->failure = true;
|
||||||
static_activeTest->failureMessage = msg;
|
static_activeTest->failureMessage = msg;
|
||||||
static_activeTest->failureFileName = ctx.from_nasal<string>(naGetSourceFile(ctx.c_ctx(), 0));
|
static_activeTest->failureFileName = ctx.from_nasal<std::string>(naGetSourceFile(ctx.c_ctx(), 0));
|
||||||
static_activeTest->failLineNumber = naGetLine(ctx.c_ctx(), 0);
|
static_activeTest->failLineNumber = naGetLine(ctx.c_ctx(), 0);
|
||||||
|
|
||||||
ctx.runtimeError("Test failed");
|
ctx.runtimeError("Test failed");
|
||||||
|
@ -106,16 +95,16 @@ static naRef f_assert_equal(const nasal::CallContext& ctx )
|
||||||
{
|
{
|
||||||
naRef argA = ctx.requireArg<naRef>(0);
|
naRef argA = ctx.requireArg<naRef>(0);
|
||||||
naRef argB = ctx.requireArg<naRef>(1);
|
naRef argB = ctx.requireArg<naRef>(1);
|
||||||
auto msg = ctx.getArg<string>(2, "assert_equal failed");
|
auto msg = ctx.getArg<std::string>(2, "assert_equal failed");
|
||||||
|
|
||||||
bool same = nasalStructEqual(ctx.c_ctx(), argA, argB);
|
bool same = nasalStructEqual(ctx.c_ctx(), argA, argB);
|
||||||
if (!same) {
|
if (!same) {
|
||||||
string aStr = ctx.from_nasal<string>(argA);
|
std::string aStr = ctx.from_nasal<std::string>(argA);
|
||||||
string bStr = ctx.from_nasal<string>(argB);
|
std::string bStr = ctx.from_nasal<std::string>(argB);
|
||||||
msg += "; expected:" + aStr + ", actual:" + bStr;
|
msg += "; expected:" + aStr + ", actual:" + bStr;
|
||||||
static_activeTest->failure = true;
|
static_activeTest->failure = true;
|
||||||
static_activeTest->failureMessage = msg;
|
static_activeTest->failureMessage = msg;
|
||||||
static_activeTest->failureFileName = ctx.from_nasal<string>(naGetSourceFile(ctx.c_ctx(), 0));
|
static_activeTest->failureFileName = ctx.from_nasal<std::string>(naGetSourceFile(ctx.c_ctx(), 0));
|
||||||
static_activeTest->failLineNumber = naGetLine(ctx.c_ctx(), 0);
|
static_activeTest->failLineNumber = naGetLine(ctx.c_ctx(), 0);
|
||||||
ctx.runtimeError(msg.c_str());
|
ctx.runtimeError(msg.c_str());
|
||||||
}
|
}
|
||||||
|
@ -129,14 +118,14 @@ static naRef f_assert_doubles_equal(const nasal::CallContext& ctx )
|
||||||
double argB = ctx.requireArg<double>(1);
|
double argB = ctx.requireArg<double>(1);
|
||||||
double tolerance = ctx.requireArg<double>(2);
|
double tolerance = ctx.requireArg<double>(2);
|
||||||
|
|
||||||
auto msg = ctx.getArg<string>(3, "assert_doubles_equal failed");
|
auto msg = ctx.getArg<std::string>(3, "assert_doubles_equal failed");
|
||||||
|
|
||||||
const bool same = fabs(argA - argB) < tolerance;
|
const bool same = fabs(argA - argB) < tolerance;
|
||||||
if (!same) {
|
if (!same) {
|
||||||
msg += "; expected:" + std::to_string(argA) + ", actual:" + std::to_string(argB);
|
msg += "; expected:" + std::to_string(argA) + ", actual:" + std::to_string(argB);
|
||||||
static_activeTest->failure = true;
|
static_activeTest->failure = true;
|
||||||
static_activeTest->failureMessage = msg;
|
static_activeTest->failureMessage = msg;
|
||||||
static_activeTest->failureFileName = ctx.from_nasal<string>(naGetSourceFile(ctx.c_ctx(), 0));
|
static_activeTest->failureFileName = ctx.from_nasal<std::string>(naGetSourceFile(ctx.c_ctx(), 0));
|
||||||
static_activeTest->failLineNumber = naGetLine(ctx.c_ctx(), 0);
|
static_activeTest->failLineNumber = naGetLine(ctx.c_ctx(), 0);
|
||||||
ctx.runtimeError(msg.c_str());
|
ctx.runtimeError(msg.c_str());
|
||||||
}
|
}
|
||||||
|
@ -247,8 +236,8 @@ bool executeNasalTest(const SGPath& path)
|
||||||
sg_ifstream file_in(path);
|
sg_ifstream file_in(path);
|
||||||
const auto source = file_in.read_all();
|
const auto source = file_in.read_all();
|
||||||
|
|
||||||
string errors;
|
std::string errors;
|
||||||
string fileName = path.utf8Str();
|
std::string fileName = path.utf8Str();
|
||||||
naRef code = parseTestFile(ctx, fileName.c_str(),
|
naRef code = parseTestFile(ctx, fileName.c_str(),
|
||||||
source.c_str(),
|
source.c_str(),
|
||||||
source.size(), errors);
|
source.size(), errors);
|
||||||
|
|
Loading…
Add table
Reference in a new issue