Using full path when adding a file to VFS. Fixes #616.
PiperOrigin-RevId: 492204185 Change-Id: If2b2230c095fe0bb776fcc3ffda48f13d0be5cb2
This commit is contained in:
committed by
Copybara-Service
parent
b9b224bfbd
commit
89185b4af2
@@ -75,6 +75,11 @@ General
|
||||
`AVX <https://en.wikipedia.org/wiki/Advanced_Vector_Extensions>`_ instructions on x86-64 machines, which is not
|
||||
supported by Rosetta 2. (Before this version, users only get a cryptic "Illegal instruction" message.)
|
||||
|
||||
Bug fixes
|
||||
^^^^^^^^^
|
||||
|
||||
- Fixed bug in ``mj_addFileVFS`` that was causing the file path to be ignored (introduced in 2.1.4).
|
||||
|
||||
Simulate
|
||||
^^^^^^^^
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ int mj_addFileVFS(mjVFS* vfs, const char* directory, const char* filename) {
|
||||
|
||||
// allocate and read
|
||||
int filesize = 0;
|
||||
vfs->filedata[vfs->nfile] = mju_fileToMemory(filename, &filesize);
|
||||
vfs->filedata[vfs->nfile] = mju_fileToMemory(fullname, &filesize);
|
||||
if (!vfs->filedata[vfs->nfile]) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -69,3 +69,6 @@ target_link_libraries(engine_util_solve_test fixture gmock)
|
||||
|
||||
mujoco_test(engine_util_spatial_test)
|
||||
target_link_libraries(engine_util_spatial_test fixture gmock)
|
||||
|
||||
mujoco_test(engine_vfs_test)
|
||||
target_link_libraries(engine_vfs_test fixture gmock)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright 2021 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <mujoco/mujoco.h>
|
||||
#include "test/fixture.h"
|
||||
|
||||
namespace mujoco {
|
||||
namespace {
|
||||
|
||||
using ::testing::NotNull;
|
||||
using EngineVfsTest = MujocoTest;
|
||||
|
||||
TEST_F(EngineVfsTest, AddFileVFS) {
|
||||
constexpr char path[] = "engine/testdata/";
|
||||
const std::string dir = GetTestDataFilePath(path);
|
||||
std::string file = "refsite.xml";
|
||||
|
||||
std::FILE* fp = std::fopen((dir + file).c_str(), "r");
|
||||
ASSERT_THAT(fp, NotNull()) << "Input file missing.";
|
||||
std::fclose(fp);
|
||||
|
||||
auto mj_vfs = std::make_unique<mjVFS>();
|
||||
mj_defaultVFS(mj_vfs.get());
|
||||
EXPECT_THAT(mj_addFileVFS(mj_vfs.get(), dir.c_str(), file.c_str()), 0);
|
||||
EXPECT_THAT(mj_vfs->nfile, 1);
|
||||
mj_deleteFileVFS(mj_vfs.get(), file.c_str());
|
||||
mj_deleteVFS(mj_vfs.get());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace mujoco
|
||||
Reference in New Issue
Block a user