diff --git a/source/RobotAPI/libraries/aron/codegeneration/test/CMakeLists.txt b/source/RobotAPI/libraries/aron/codegeneration/test/CMakeLists.txt index e57da47b6d56c9d33a146a609c6dcba9c6c06f30..d7add84ada2fcafe2c8bf8f9f9a8d2c40e663c7d 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/test/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/codegeneration/test/CMakeLists.txt @@ -106,6 +106,25 @@ armarx_add_test( ${Simox_INCLUDE_DIR} ) +###################### +# ARON JSON EXPORT TEST +###################### +armarx_add_test( + TEST_NAME + aronJsonExportTest + TEST_FILE + aronJsonExportTest.cpp + LIBS + SimoxUtility # Simox::SimoxUtility + ArmarXCore + RobotAPI::aron + ARON_FILES + aron/OptionalTest.xml + aron/MatrixTest.xml + INCLUDE_DIRECTORIES + ${Simox_INCLUDE_DIR} +) + ######################## # ARON RANDOMIZED TEST # ######################## diff --git a/source/RobotAPI/libraries/aron/codegeneration/test/aronJsonExportTest.cpp b/source/RobotAPI/libraries/aron/codegeneration/test/aronJsonExportTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dea56801557a7890824c8f03d5b2cf5b2711d9a0 --- /dev/null +++ b/source/RobotAPI/libraries/aron/codegeneration/test/aronJsonExportTest.cpp @@ -0,0 +1,86 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX 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, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::aron + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2019 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#define BOOST_TEST_MODULE RobotAPI::ArmarXLibraries::aron + +#define ARMARX_BOOST_TEST + +// STD/STL +#include <iostream> +#include <cstdlib> +#include <ctime> +#include <numeric> +#include <fstream> + +// Test +#include <RobotAPI/Test.h> + +// ArmarX +#include <ArmarXCore/libraries/cppgen/CppMethod.h> +#include <ArmarXCore/libraries/cppgen/CppClass.h> +#include <RobotAPI/libraries/aron/core/Exception.h> + +// Aron +#include <RobotAPI/libraries/aron/core/data/variant/All.h> +#include <RobotAPI/libraries/aron/core/type/variant/All.h> +#include <RobotAPI/libraries/aron/core/data/rw/writer/nlohmannJSON/NlohmannJSONWriter.h> +#include <RobotAPI/libraries/aron/core/data/rw/reader/nlohmannJSON/NlohmannJSONReader.h> +#include <RobotAPI/libraries/aron/core/type/rw/writer/nlohmannJSON/NlohmannJSONWriter.h> +#include <RobotAPI/libraries/aron/core/type/rw/reader/nlohmannJSON/NlohmannJSONReader.h> + +// Generated File +#include <RobotAPI/libraries/aron/codegeneration/test/aron/MatrixTest.aron.generated.h> +#include <RobotAPI/libraries/aron/codegeneration/test/aron/OptionalTest.aron.generated.h> + +using namespace armarx; +using namespace aron; + +BOOST_AUTO_TEST_CASE(AronJsonExportTest) +{ + std::cout << "Aron json export test" << std::endl; + OptionalTest clazz; + + { + auto t = clazz.ToAronType(); + + auto type_writer = type::writer::NlohmannJSONWriter(); + auto type_json = clazz.writeType(type_writer); + + std::ofstream type_ofs("/tmp/aronJsonExportTestType.json"); + type_ofs << type_json.dump(2); + + auto data_writer = data::writer::NlohmannJSONWriter(); + auto data_json = clazz.write(data_writer); + + std::ofstream data_ofs("/tmp/aronJsonExportTestData.json"); + data_ofs << data_json.dump(2); + } + + + // Try to read data again + auto data_reader = data::reader::NlohmannJSONReader(); + std::ifstream data_ifs("/tmp/aronJsonExportTestData.json"); + auto data_json = nlohmann::json::parse(data_ifs); + + clazz.read(data_reader, data_json); +} +