From f30db1f2e75e16ea0faa7f8184efbbaee03540aa Mon Sep 17 00:00:00 2001 From: Tom Vierjahn Date: Thu, 29 Mar 2018 16:56:42 +0200 Subject: [PATCH] Split nest_test_data into data and helpers --- niv/include/niv/testing/conduit_schema.hpp | 60 +++++++++++ .../testing/{nest_test_data.hpp => data.hpp} | 99 +++++-------------- niv/include/niv/testing/helpers.hpp | 57 +++++++++++ niv/src/consumer/arbor_multimeter.cpp | 2 +- .../testing/{nest_test_data.cpp => data.cpp} | 55 +---------- niv/src/testing/helpers.cpp | 83 ++++++++++++++++ .../src/consumer/test_arbor_multimeter.cpp | 8 +- niv/tests/src/consumer/test_device.cpp | 2 +- niv/tests/src/consumer/test_integration.cpp | 3 +- niv/tests/src/consumer/test_multimeter.cpp | 2 +- .../src/consumer/test_nest_multimeter.cpp | 8 +- niv/tests/src/consumer/test_receiver.cpp | 10 +- niv/tests/src/exchange/test_node_storage.cpp | 18 ++-- .../src/exchange/test_relay_shared_memory.cpp | 16 +-- .../test_relay_shared_memory_mutex.cpp | 18 ++-- .../test_relay_shared_memory_threaded.cpp | 4 +- niv/tests/src/exchange/test_shared_memory.cpp | 46 ++++----- .../src/producer/test_arbor_multimeter.cpp | 6 +- .../src/producer/test_nest_multimeter.cpp | 4 +- niv/tests/src/producer/test_sender.cpp | 6 +- .../src/producer/test_spike_detector.cpp | 2 +- niv/tests/src/test_conduit.cpp | 69 +++++++------ .../testing/{nest_test_data.cpp => data.cpp} | 30 +----- pyniv/src/testing/helpers.cpp | 65 ++++++++++++ pyniv/src/testing/testing.cpp | 8 +- pyniv/tests/src/consumer/test_receiver.py | 8 +- 26 files changed, 416 insertions(+), 273 deletions(-) create mode 100644 niv/include/niv/testing/conduit_schema.hpp rename niv/include/niv/testing/{nest_test_data.hpp => data.hpp} (76%) create mode 100644 niv/include/niv/testing/helpers.hpp rename niv/src/testing/{nest_test_data.cpp => data.cpp} (69%) create mode 100644 niv/src/testing/helpers.cpp rename pyniv/src/testing/{nest_test_data.cpp => data.cpp} (78%) create mode 100644 pyniv/src/testing/helpers.cpp diff --git a/niv/include/niv/testing/conduit_schema.hpp b/niv/include/niv/testing/conduit_schema.hpp new file mode 100644 index 0000000..fc7bad8 --- /dev/null +++ b/niv/include/niv/testing/conduit_schema.hpp @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017-2018 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// 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. +//------------------------------------------------------------------------------ + +#ifndef NIV_INCLUDE_NIV_TESTING_CONDUIT_SCHEMA_HPP_ +#define NIV_INCLUDE_NIV_TESTING_CONDUIT_SCHEMA_HPP_ + +namespace niv { +namespace testing { +namespace conduit_schema { + +template +inline std::string OpenTag(T tag) { + std::stringstream s; + s << '\"' << tag << '\"' << ":{ \n"; + return s.str(); +} + +inline std::string CloseTag() { return std::string("} \n"); } +inline std::string CloseTagNext() { return std::string("}, \n"); } + +inline std::string DoubleData(std::size_t offset) { + std::stringstream s; + s << "dtype:float64, "; + s << "number_of_elements:1, "; + s << "offset:" << offset << ", "; + s << "stride:8, "; + s << "element_bytes:8"; + s << "\n"; + return s.str(); +} + +inline void RemoveNextIndicator(std::stringstream* s) { + s->clear(); + s->seekp(s->str().size() - 3); + *s << " \n"; +} + +} // namespace conduit_schema +} // namespace testing +} // namespace niv + +#endif // NIV_INCLUDE_NIV_TESTING_CONDUIT_SCHEMA_HPP_ diff --git a/niv/include/niv/testing/nest_test_data.hpp b/niv/include/niv/testing/data.hpp similarity index 76% rename from niv/include/niv/testing/nest_test_data.hpp rename to niv/include/niv/testing/data.hpp index baf6ac6..c7d87fb 100644 --- a/niv/include/niv/testing/nest_test_data.hpp +++ b/niv/include/niv/testing/data.hpp @@ -19,29 +19,21 @@ // limitations under the License. //------------------------------------------------------------------------------ -#ifndef NIV_INCLUDE_NIV_NEST_TEST_DATA_HPP_ -#define NIV_INCLUDE_NIV_NEST_TEST_DATA_HPP_ +#ifndef NIV_INCLUDE_NIV_TESTING_DATA_HPP_ +#define NIV_INCLUDE_NIV_TESTING_DATA_HPP_ #include #include #include "niv/producer/nest_multimeter.hpp" -namespace niv { - -class Testing { - public: - Testing() = delete; - Testing(const Testing&) = delete; - Testing(Testing&&) = delete; - ~Testing() = delete; - - Testing& operator=(const Testing&) = delete; - Testing& operator=(Testing&&) = delete; -}; +#include "niv/testing/conduit_schema.hpp" +namespace niv { namespace testing { +class Data; + #if defined __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-variable" @@ -126,14 +118,14 @@ inline std::string PathFor(const std::string& device_name, } // clang-format off -static const std::vector ANY_VALUES{ +static const std::vector ANY_DATA_VALUES{ 0.111, 0.112, 0.113, 0.121, 0.122, 0.123, 0.131, 0.132, 0.133, 0.211, 0.212, 0.213, 0.221, 0.222, 0.223, 0.231, 0.232, 0.233, 0.311, 0.312, 0.313, 0.321, 0.322, 0.323, 0.331, 0.332, 0.333}; // clang-format on -static const double ANY_VALUE{ANY_VALUES[0]}; -static const std::vector ANY_VALUES_FOR_ATTRIBUTES{ - ANY_VALUES[0], ANY_VALUES[3], ANY_VALUES[6]}; +static const double ANY_DATA_VALUE{ANY_DATA_VALUES[0]}; +static const std::vector ANY_DATA_VALUES_FOR_ATTRIBUTES{ + ANY_DATA_VALUES[0], ANY_DATA_VALUES[3], ANY_DATA_VALUES[6]}; static const std::size_t TIME_STRIDE{9}; static const std::size_t ATTRIBUTE_STRIDE{3}; @@ -144,7 +136,7 @@ inline double ValueAt(std::size_t time_id, std::size_t attribute_id, const std::size_t index = time_id * TIME_STRIDE + attribute_id * ATTRIBUTE_STRIDE + neuron_id * ID_STRIDE; - return ANY_VALUES[index]; + return ANY_DATA_VALUES[index]; } static const std::size_t ANY_TIME_OFFSET{ANY_INDEX * niv::testing::TIME_STRIDE}; @@ -165,81 +157,42 @@ static const std::size_t THIRD_ID_OFFSET{THIRD_INDEX * niv::testing::ID_STRIDE}; static const std::vector ID_OFFSETS{ ANY_ID_OFFSET, ANOTHER_ID_OFFSET, THIRD_ID_OFFSET}; -template -inline std::string OpenTag(T tag) { - std::stringstream s; - s << '\"' << tag << '\"' << ":{ \n"; - return s.str(); -} - -inline std::string CloseTag() { return std::string("} \n"); } -inline std::string CloseTagNext() { return std::string("}, \n"); } - -inline std::string DoubleData(std::size_t offset) { - std::stringstream s; - s << "dtype:float64, "; - s << "number_of_elements:1, "; - s << "offset:" << offset << ", "; - s << "stride:8, "; - s << "element_bytes:8"; - s << "\n"; - return s.str(); -} - -inline void RemoveNextIndicator(std::stringstream* s) { - s->clear(); - s->seekp(s->str().size() - 3); - *s << " \n"; -} - inline static const std::string AnyNestDataSchema() { std::stringstream s; std::size_t offset = 0; const std::size_t datum_size = 8; s << "{\n"; - s << " " << OpenTag(ANY_MULTIMETER_NAME); + s << " " << conduit_schema::OpenTag(ANY_MULTIMETER_NAME); for (auto time : ANY_TIMES) { - s << " " << OpenTag(time); + s << " " << conduit_schema::OpenTag(time); for (auto attribute : ANY_ATTRIBUTES) { - s << " " << OpenTag(attribute); + s << " " << conduit_schema::OpenTag(attribute); for (auto id : ANY_IDS) { - s << " " << OpenTag(id); - s << " " << DoubleData((offset++) * datum_size); - s << " " << CloseTagNext(); + s << " " << conduit_schema::OpenTag(id); + s << " " + << conduit_schema::DoubleData((offset++) * datum_size); + s << " " << conduit_schema::CloseTagNext(); } - RemoveNextIndicator(&s); - s << " " << CloseTagNext(); + conduit_schema::RemoveNextIndicator(&s); + s << " " << conduit_schema::CloseTagNext(); } - RemoveNextIndicator(&s); - s << " " << CloseTagNext(); + conduit_schema::RemoveNextIndicator(&s); + s << " " << conduit_schema::CloseTagNext(); } - RemoveNextIndicator(&s); - s << " " << CloseTag(); + conduit_schema::RemoveNextIndicator(&s); + s << " " << conduit_schema::CloseTag(); s << "}"; return s.str(); } static conduit::Node ANY_NEST_DATA{ - AnyNestDataSchema(), const_cast(ANY_VALUES.data()), false}; + AnyNestDataSchema(), const_cast(ANY_DATA_VALUES.data()), false}; #if defined __GNUC__ #pragma GCC diagnostic pop #endif -void Send(const conduit::Node& node); - -conduit::Node AnyNode(); - -conduit::Node AnotherNode(); - -conduit::Node Update(); - -conduit::Node UpdatedNode(); -conduit::Node UpdatedNodeAllZeros(); - -conduit::Node ADifferentNode(); - } // namespace testing } // namespace niv -#endif // NIV_INCLUDE_NIV_NEST_TEST_DATA_HPP_ +#endif // NIV_INCLUDE_NIV_TESTING_DATA_HPP_ diff --git a/niv/include/niv/testing/helpers.hpp b/niv/include/niv/testing/helpers.hpp new file mode 100644 index 0000000..f95e2ca --- /dev/null +++ b/niv/include/niv/testing/helpers.hpp @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017-2018 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// 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. +//------------------------------------------------------------------------------ + +#ifndef NIV_INCLUDE_NIV_TESTING_HELPERS_HPP_ +#define NIV_INCLUDE_NIV_TESTING_HELPERS_HPP_ + +#include "conduit/conduit_node.hpp" + +namespace niv { +namespace testing { + +class Helpers; + +void Send(const conduit::Node& node); + +conduit::Node AnyNode(); +conduit::Node AnotherNode(); + +conduit::Node AnyUpdate(); +conduit::Node UpdatedNode(); +conduit::Node UpdatedNodeAllZeros(); + +conduit::Node ADifferentNode(); + +static const conduit::Node ANY_NODE{AnyNode()}; +static const conduit::Node ANOTHER_NODE{AnotherNode()}; + +static const conduit::Node ANY_UPDATE{AnyUpdate()}; +static const conduit::Node UPDATED_NODE{UpdatedNode()}; +static const conduit::Node UPDATED_NODE_ALL_ZEROS{UpdatedNodeAllZeros()}; + +static const conduit::Node A_DIFFERENT_NODE{ADifferentNode()}; + +static const double ANY_VALUE{4.123}; + +} // namespace testing +} // namespace niv + +#endif // NIV_INCLUDE_NIV_TESTING_HELPERS_HPP_ diff --git a/niv/src/consumer/arbor_multimeter.cpp b/niv/src/consumer/arbor_multimeter.cpp index 60284f9..06300ac 100644 --- a/niv/src/consumer/arbor_multimeter.cpp +++ b/niv/src/consumer/arbor_multimeter.cpp @@ -28,7 +28,7 @@ #include "conduit/conduit_node.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/data.hpp" namespace niv { namespace consumer { diff --git a/niv/src/testing/nest_test_data.cpp b/niv/src/testing/data.cpp similarity index 69% rename from niv/src/testing/nest_test_data.cpp rename to niv/src/testing/data.cpp index 35fbd60..3a1a696 100644 --- a/niv/src/testing/nest_test_data.cpp +++ b/niv/src/testing/data.cpp @@ -19,7 +19,7 @@ // limitations under the License. //------------------------------------------------------------------------------ -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/data.hpp" #include #include @@ -59,58 +59,5 @@ std::vector ThirdAttributesValues(double time) { std::string AnyMultimeterName() { return "multimeter A"; } -void Send(const conduit::Node& node) { - exchange::RelaySharedMemory relay; - relay.Send(node); -} - -conduit::Node AnyNode() { - conduit::Node node; - node["A/B/C"] = 3.1415; - node["A/B/D"] = 4.124; - node["A/E"] = 42.0; - return node; -} - -conduit::Node AnotherNode() { - conduit::Node node; - node["A/B/C"] = 2.0 * 3.1415; - node["A/B/D"] = 3.0 * 4.124; - node["A/E"] = 4.0 * 42.0; - return node; -} - -conduit::Node Update() { - conduit::Node node; - node["A/B/F"] = 2.0 * 3.1415; - node["A/B/G"] = 3.0 * 4.124; - node["A/H"] = 4.0 * 42.0; - return node; -} - -conduit::Node UpdatedNode() { - conduit::Node node; - node["A/B/C"] = 3.1415; - node["A/B/D"] = 4.124; - node["A/E"] = 42.0; - node["A/B/F"] = 2.0 * 3.1415; - node["A/B/G"] = 3.0 * 4.124; - node["A/H"] = 4.0 * 42.0; - return node; -} - -conduit::Node UpdatedNodeAllZeros() { - conduit::Node node; - node["A/B/C"] = 0.0; - node["A/B/D"] = 0.0; - node["A/E"] = 0.0; - node["A/B/F"] = 0.0; - node["A/B/G"] = 0.0; - node["A/H"] = 0.0; - return node; -} - -conduit::Node ADifferentNode() { return Update(); } - } // namespace testing } // namespace niv diff --git a/niv/src/testing/helpers.cpp b/niv/src/testing/helpers.cpp new file mode 100644 index 0000000..8a780da --- /dev/null +++ b/niv/src/testing/helpers.cpp @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017-2018 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// 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 "niv/testing/helpers.hpp" + +#include "niv/exchange/relay_shared_memory.hpp" + +namespace niv { +namespace testing { + +void Send(const conduit::Node& node) { + exchange::RelaySharedMemory relay; + relay.Send(node); +} + +conduit::Node AnyNode() { + conduit::Node node; + node["A/B/C"] = 3.1415; + node["A/B/D"] = 4.124; + node["A/E"] = 42.0; + return node; +} + +conduit::Node AnotherNode() { + conduit::Node node; + node["A/B/C"] = 2.0 * 3.1415; + node["A/B/D"] = 3.0 * 4.124; + node["A/E"] = 4.0 * 42.0; + return node; +} + +conduit::Node AnyUpdate() { + conduit::Node node; + node["A/B/F"] = 2.0 * 3.1415; + node["A/B/G"] = 3.0 * 4.124; + node["A/H"] = 4.0 * 42.0; + return node; +} + +conduit::Node UpdatedNode() { + conduit::Node node; + node["A/B/C"] = 3.1415; + node["A/B/D"] = 4.124; + node["A/E"] = 42.0; + node["A/B/F"] = 2.0 * 3.1415; + node["A/B/G"] = 3.0 * 4.124; + node["A/H"] = 4.0 * 42.0; + return node; +} + +conduit::Node UpdatedNodeAllZeros() { + conduit::Node node; + node["A/B/C"] = 0.0; + node["A/B/D"] = 0.0; + node["A/E"] = 0.0; + node["A/B/F"] = 0.0; + node["A/B/G"] = 0.0; + node["A/H"] = 0.0; + return node; +} + +conduit::Node ADifferentNode() { return AnyUpdate(); } + +} // namespace testing +} // namespace niv diff --git a/niv/tests/src/consumer/test_arbor_multimeter.cpp b/niv/tests/src/consumer/test_arbor_multimeter.cpp index 0ed6462..0cc5bab 100644 --- a/niv/tests/src/consumer/test_arbor_multimeter.cpp +++ b/niv/tests/src/consumer/test_arbor_multimeter.cpp @@ -25,7 +25,7 @@ #include "catch/Catch.hpp" #include "niv/consumer/arbor_multimeter.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/data.hpp" #include "test_utilities/vector_all_nan_or_empty.hpp" @@ -44,7 +44,7 @@ SCENARIO("ArborMultimeter retrieves datum for time, attribute, neuron", const std::size_t DATUM_OFFSET{niv::testing::ANY_TIME_OFFSET + niv::testing::ANOTHER_ATTRIBUTE_OFFSET + niv::testing::THIRD_ID_OFFSET}; - REQUIRE(datum == Approx(niv::testing::ANY_VALUES[DATUM_OFFSET])); + REQUIRE(datum == Approx(niv::testing::ANY_DATA_VALUES[DATUM_OFFSET])); } } @@ -92,7 +92,7 @@ SCENARIO("ArborMultimeter provides time series data", const auto DATUM_INDEX{time_offset + niv::testing::ANOTHER_ATTRIBUTE_OFFSET + niv::testing::THIRD_ID_OFFSET}; - expected.push_back(niv::testing::ANY_VALUES[DATUM_INDEX]); + expected.push_back(niv::testing::ANY_DATA_VALUES[DATUM_INDEX]); } const std::vector nans(niv::testing::ANY_TIMES_STRING.size(), std::nan("")); @@ -155,7 +155,7 @@ SCENARIO("ArborMultimeter provides timestep data for all neurons", const auto ID_OFFSET{i * niv::testing::ID_STRIDE}; const auto DATUM_INDEX{niv::testing::THIRD_TIME_OFFSET + niv::testing::ANOTHER_ATTRIBUTE_OFFSET + ID_OFFSET}; - expected.push_back(niv::testing::ANY_VALUES[DATUM_INDEX]); + expected.push_back(niv::testing::ANY_DATA_VALUES[DATUM_INDEX]); } GIVEN("a multimeter providing access to some data") { diff --git a/niv/tests/src/consumer/test_device.cpp b/niv/tests/src/consumer/test_device.cpp index 508c31a..5859154 100644 --- a/niv/tests/src/consumer/test_device.cpp +++ b/niv/tests/src/consumer/test_device.cpp @@ -25,7 +25,7 @@ #include "catch/catch.hpp" #include "niv/consumer/device.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/data.hpp" namespace Catch { namespace Matchers { diff --git a/niv/tests/src/consumer/test_integration.cpp b/niv/tests/src/consumer/test_integration.cpp index 4a3adbf..03b1005 100644 --- a/niv/tests/src/consumer/test_integration.cpp +++ b/niv/tests/src/consumer/test_integration.cpp @@ -26,7 +26,8 @@ #include "niv/consumer/backend.hpp" #include "niv/consumer/nest_multimeter.hpp" #include "niv/consumer/receiver.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/data.hpp" +#include "niv/testing/helpers.hpp" SCENARIO("Consumer integration", "[niv][integration]") { GIVEN("The required objects") { diff --git a/niv/tests/src/consumer/test_multimeter.cpp b/niv/tests/src/consumer/test_multimeter.cpp index 8b769d3..8b98b7c 100644 --- a/niv/tests/src/consumer/test_multimeter.cpp +++ b/niv/tests/src/consumer/test_multimeter.cpp @@ -22,7 +22,7 @@ #include "catch/catch.hpp" #include "niv/consumer/multimeter.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/data.hpp" SCENARIO("consumer::Multimeter lists attributes for a timestep", "[niv][niv::consumer][niv::consumer::Multimeter]") { diff --git a/niv/tests/src/consumer/test_nest_multimeter.cpp b/niv/tests/src/consumer/test_nest_multimeter.cpp index 30a46c1..e6c76a5 100644 --- a/niv/tests/src/consumer/test_nest_multimeter.cpp +++ b/niv/tests/src/consumer/test_nest_multimeter.cpp @@ -26,7 +26,7 @@ #include "conduit/conduit_node.hpp" #include "niv/consumer/nest_multimeter.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/data.hpp" #include "test_utilities/vector_all_nan_or_empty.hpp" @@ -44,7 +44,7 @@ SCENARIO("NestMultimeter retrieves datum for time, attribute, neuron", const std::size_t DATUM_OFFSET{niv::testing::ANY_TIME_OFFSET + niv::testing::ANOTHER_ATTRIBUTE_OFFSET + niv::testing::THIRD_ID_OFFSET}; - REQUIRE(datum == Approx(niv::testing::ANY_VALUES[DATUM_OFFSET])); + REQUIRE(datum == Approx(niv::testing::ANY_DATA_VALUES[DATUM_OFFSET])); } } @@ -92,7 +92,7 @@ SCENARIO("NestMultimeter provides time series data", const auto DATUM_INDEX{time_offset + niv::testing::ANOTHER_ATTRIBUTE_OFFSET + niv::testing::THIRD_ID_OFFSET}; - expected.push_back(niv::testing::ANY_VALUES[DATUM_INDEX]); + expected.push_back(niv::testing::ANY_DATA_VALUES[DATUM_INDEX]); } const std::vector nans(niv::testing::ANY_TIMES_STRING.size(), std::nan("")); @@ -154,7 +154,7 @@ SCENARIO("NestMultimeter provides timestep data for all neurons", const auto ID_OFFSET{i * niv::testing::ID_STRIDE}; const auto DATUM_INDEX{niv::testing::THIRD_TIME_OFFSET + niv::testing::ANOTHER_ATTRIBUTE_OFFSET + ID_OFFSET}; - expected.push_back(niv::testing::ANY_VALUES[DATUM_INDEX]); + expected.push_back(niv::testing::ANY_DATA_VALUES[DATUM_INDEX]); } GIVEN("a multimeter providing access to some data") { diff --git a/niv/tests/src/consumer/test_receiver.cpp b/niv/tests/src/consumer/test_receiver.cpp index c899577..d2b7b9a 100644 --- a/niv/tests/src/consumer/test_receiver.cpp +++ b/niv/tests/src/consumer/test_receiver.cpp @@ -23,7 +23,7 @@ #include "niv/consumer/receiver.hpp" #include "niv/exchange/relay_shared_memory.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/helpers.hpp" #include "conduit_node_helper.hpp" @@ -36,17 +36,17 @@ SCENARIO("received data is aggregated in the consumer::Receiver", niv::exchange::RelaySharedMemory sender; WHEN("Data is sent and a receive is triggered") { - sender.Send(niv::testing::AnyNode()); + sender.Send(niv::testing::ANY_NODE); receiver.Receive(); THEN("it is received correctly") { - REQUIRE_THAT(receiving_node, Equals(niv::testing::AnyNode())); + REQUIRE_THAT(receiving_node, Equals(niv::testing::ANY_NODE)); } WHEN("an update is sent and a receive is triggered") { - sender.Send(niv::testing::Update()); + sender.Send(niv::testing::ANY_UPDATE); receiver.Receive(); THEN("then the data has been updated") { - REQUIRE_THAT(receiving_node, Equals(niv::testing::UpdatedNode())); + REQUIRE_THAT(receiving_node, Equals(niv::testing::UPDATED_NODE)); } } } diff --git a/niv/tests/src/exchange/test_node_storage.cpp b/niv/tests/src/exchange/test_node_storage.cpp index a972c53..1f1e3b2 100644 --- a/niv/tests/src/exchange/test_node_storage.cpp +++ b/niv/tests/src/exchange/test_node_storage.cpp @@ -26,7 +26,7 @@ #include "catch/catch.hpp" #include "niv/exchange/node_storage.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/helpers.hpp" #include "conduit_node_helper.hpp" @@ -59,9 +59,9 @@ SCENARIO("storing and reading a node", "[niv][niv::NodeStorage]") { GIVEN("a node storage") { ::NodeStorage storage; WHEN("a node is stored") { - storage.Store(niv::testing::AnyNode()); + storage.Store(niv::testing::ANY_NODE); THEN("it can be read") { - REQUIRE_THAT(storage.Read(), Equals(niv::testing::AnyNode())); + REQUIRE_THAT(storage.Read(), Equals(niv::testing::ANY_NODE)); } } } @@ -72,7 +72,7 @@ SCENARIO("storing and reading a node yields contifguous data", GIVEN("a node storage") { ::NodeStorage storage; WHEN("a node is stored and retrieved") { - storage.Store(niv::testing::AnyNode()); + storage.Store(niv::testing::ANY_NODE); conduit::Node read{storage.Read()}; THEN("the read node's data is contiguous") { REQUIRE(read.is_contiguous()); @@ -85,13 +85,13 @@ SCENARIO("a node can be stored and read multiple times", "[niv][niv::NodeStorage]") { GIVEN("a node stored and read back") { ::NodeStorage storage; - storage.Store(niv::testing::AnyNode()); + storage.Store(niv::testing::ANY_NODE); storage.Store(storage.Read()); WHEN("the node is read") { conduit::Node read_node{storage.Read()}; THEN("it is equal to the initial one") { - REQUIRE_THAT(read_node, Equals(niv::testing::AnyNode())); + REQUIRE_THAT(read_node, Equals(niv::testing::ANY_NODE)); } } } @@ -100,13 +100,13 @@ SCENARIO("a node can be stored and read multiple times", SCENARIO("a node can be listening to changes", "[niv][niv::NodeStorage]") { GIVEN("a node listening to data") { ::NodeStorage storage; - storage.Store(niv::testing::AnyNode()); + storage.Store(niv::testing::ANY_NODE); conduit::Node listening_node{storage.Listen()}; WHEN("stored data is changed") { - storage.Store(niv::testing::AnotherNode()); + storage.Store(niv::testing::ANOTHER_NODE); THEN("the listening node gets the change") { - REQUIRE_THAT(listening_node, Equals(niv::testing::AnotherNode())); + REQUIRE_THAT(listening_node, Equals(niv::testing::ANOTHER_NODE)); } } } diff --git a/niv/tests/src/exchange/test_relay_shared_memory.cpp b/niv/tests/src/exchange/test_relay_shared_memory.cpp index 3cb05b8..8e776ef 100644 --- a/niv/tests/src/exchange/test_relay_shared_memory.cpp +++ b/niv/tests/src/exchange/test_relay_shared_memory.cpp @@ -27,7 +27,7 @@ #include "niv/exchange/relay_shared_memory.hpp" #include "niv/exchange/shared_memory.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/helpers.hpp" #include "conduit_node_helper.hpp" @@ -37,13 +37,13 @@ SCENARIO("Data gets transported", "[niv][niv::RelaySharedMemory]") { niv::exchange::RelaySharedMemory simulation_relay; WHEN("a node is sent via the simulation relay") { - simulation_relay.Send(niv::testing::AnyNode()); + simulation_relay.Send(niv::testing::ANY_NODE); WHEN("data is received via the visualization relay") { conduit::Node received_node{visualization_relay.Receive()}; THEN("received data matches original data") { - REQUIRE_THAT(received_node, Equals(niv::testing::AnyNode())); + REQUIRE_THAT(received_node, Equals(niv::testing::ANY_NODE)); } } } @@ -54,14 +54,14 @@ SCENARIO("data in relay gets updated on sending update", "[niv][niv::RelaySharedMemory]") { GIVEN("a relay storing data") { niv::exchange::RelaySharedMemory simulation_relay; - simulation_relay.Send(niv::testing::AnyNode()); + simulation_relay.Send(niv::testing::ANY_NODE); WHEN("an update gets sent to the relay") { - simulation_relay.Send(niv::testing::Update()); + simulation_relay.Send(niv::testing::ANY_UPDATE); WHEN("the node is received from the relay") { conduit::Node received_node{simulation_relay.Receive()}; THEN("the received node includes the update") { - REQUIRE_THAT(received_node, Equals(niv::testing::UpdatedNode())); + REQUIRE_THAT(received_node, Equals(niv::testing::UPDATED_NODE)); } } } @@ -72,7 +72,7 @@ SCENARIO("Data in relay is cleared on receive", "[niv][niv::RelaySharedMemory]") { GIVEN("A synchronized relay with some data") { niv::exchange::RelaySharedMemory relay; - relay.Send(niv::testing::AnyNode()); + relay.Send(niv::testing::ANY_NODE); WHEN("Data is received") { auto node{relay.Receive()}; @@ -98,7 +98,7 @@ SCENARIO("Relay's emptyness is passed throug shared memory", } WHEN("Data is sent") { - relay_segment.Send(niv::testing::AnyNode()); + relay_segment.Send(niv::testing::ANY_NODE); THEN("both relays are not empty.") { REQUIRE_FALSE(relay_segment.IsEmpty()); REQUIRE_FALSE(relay_access.IsEmpty()); diff --git a/niv/tests/src/exchange/test_relay_shared_memory_mutex.cpp b/niv/tests/src/exchange/test_relay_shared_memory_mutex.cpp index 473a0b2..f61a500 100644 --- a/niv/tests/src/exchange/test_relay_shared_memory_mutex.cpp +++ b/niv/tests/src/exchange/test_relay_shared_memory_mutex.cpp @@ -24,7 +24,7 @@ #include "catch/catch.hpp" #include "niv/exchange/relay_shared_memory.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/helpers.hpp" SCENARIO("Mutex does not stall multiple sends/receives", "[niv][niv::RelaySharedMemory]") { @@ -33,30 +33,30 @@ SCENARIO("Mutex does not stall multiple sends/receives", niv::exchange::RelaySharedMemory relay_access; THEN("send, receive works") { - relay_segment.Send(niv::testing::AnyNode()); + relay_segment.Send(niv::testing::ANY_NODE); relay_access.Receive(); } THEN("receive, send works") { relay_access.Receive(); - relay_segment.Send(niv::testing::AnyNode()); + relay_segment.Send(niv::testing::ANY_NODE); } THEN("send, send, receive works") { - relay_segment.Send(niv::testing::AnyNode()); - relay_segment.Send(niv::testing::AnotherNode()); + relay_segment.Send(niv::testing::ANY_NODE); + relay_segment.Send(niv::testing::ANOTHER_NODE); relay_access.Receive(); } THEN("send, receive, send, receive works") { - relay_segment.Send(niv::testing::AnyNode()); + relay_segment.Send(niv::testing::ANY_NODE); relay_access.Receive(); - relay_segment.Send(niv::testing::AnotherNode()); + relay_segment.Send(niv::testing::ANOTHER_NODE); } THEN("receive, send, send, receive works") { - relay_segment.Send(niv::testing::AnyNode()); - relay_segment.Send(niv::testing::AnotherNode()); + relay_segment.Send(niv::testing::ANY_NODE); + relay_segment.Send(niv::testing::ANOTHER_NODE); relay_access.Receive(); } } diff --git a/niv/tests/src/exchange/test_relay_shared_memory_threaded.cpp b/niv/tests/src/exchange/test_relay_shared_memory_threaded.cpp index 79810c1..99dd787 100644 --- a/niv/tests/src/exchange/test_relay_shared_memory_threaded.cpp +++ b/niv/tests/src/exchange/test_relay_shared_memory_threaded.cpp @@ -26,7 +26,7 @@ #include "catch/catch.hpp" #include "niv/exchange/relay_shared_memory.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/helpers.hpp" namespace { @@ -38,7 +38,7 @@ void Send(niv::exchange::RelaySharedMemory* relay) { for (auto i = 0u; i < 10; ++i) { const int wait = distribution(generator); std::this_thread::sleep_for(std::chrono::milliseconds(wait)); - relay->Send(niv::testing::AnyNode()); + relay->Send(niv::testing::ANY_NODE); } } diff --git a/niv/tests/src/exchange/test_shared_memory.cpp b/niv/tests/src/exchange/test_shared_memory.cpp index 9e0f75f..a8fcbe1 100644 --- a/niv/tests/src/exchange/test_shared_memory.cpp +++ b/niv/tests/src/exchange/test_shared_memory.cpp @@ -24,7 +24,7 @@ #include "conduit/conduit_node.hpp" #include "niv/exchange/shared_memory.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/helpers.hpp" #include "conduit_node_helper.hpp" @@ -43,13 +43,13 @@ SCENARIO("Shared memory creation", "[niv][niv::SharedMemory]") { WHEN("I store data in the segment") { auto free_size_before = segment.GetFreeSize(); - segment.Store(niv::testing::AnyNode()); + segment.Store(niv::testing::ANY_NODE); auto free_size_after = segment.GetFreeSize(); THEN("we have less free space in the segment") { REQUIRE(free_size_after < free_size_before); } THEN("I can read the data") { - REQUIRE_THAT(segment.Read(), Equals(niv::testing::AnyNode())); + REQUIRE_THAT(segment.Read(), Equals(niv::testing::ANY_NODE)); } } @@ -72,13 +72,13 @@ SCENARIO("write updated node to shared memory segment", "[niv][niv::SharedMemory]") { GIVEN("a shared memory segment with some data") { niv::exchange::SharedMemory segment{niv::exchange::SharedMemory::Create()}; - segment.Store(niv::testing::AnyNode()); + segment.Store(niv::testing::ANY_NODE); WHEN("a larger node is stored") { - segment.Store(niv::testing::UpdatedNode()); + segment.Store(niv::testing::UPDATED_NODE); WHEN("the node is read") { conduit::Node read_node{segment.Read()}; THEN("the content is equal to the written one") { - REQUIRE_THAT(read_node, Equals(niv::testing::UpdatedNode())); + REQUIRE_THAT(read_node, Equals(niv::testing::UPDATED_NODE)); } } } @@ -107,10 +107,10 @@ SCENARIO("Shared memory access", "[niv][niv::SharedMemory]") { niv::exchange::SharedMemory::Access()}; WHEN("data is stored in the shared memory access") { - segment_access.Store(niv::testing::AnyNode()); + segment_access.Store(niv::testing::ANY_NODE); THEN("it can be read") { - REQUIRE_THAT(segment_access.Read(), Equals(niv::testing::AnyNode())); + REQUIRE_THAT(segment_access.Read(), Equals(niv::testing::ANY_NODE)); } } } @@ -128,38 +128,38 @@ SCENARIO("storing and retrieving conduit nodes to/from shared memory", niv::exchange::SharedMemory::Access()}; WHEN("a node is stored in the shared memory segment") { - shared_memory_segment.Store(niv::testing::AnyNode()); + shared_memory_segment.Store(niv::testing::ANY_NODE); THEN("it can be read via access") { REQUIRE_THAT(shared_memory_access.Read(), - Equals(niv::testing::AnyNode())); + Equals(niv::testing::ANY_NODE)); } GIVEN("a node listening to shared memory") { conduit::Node listening_node{shared_memory_access.Listen()}; WHEN("the first node is updated and stored again") { - shared_memory_segment.Store(niv::testing::AnotherNode()); + shared_memory_segment.Store(niv::testing::ANOTHER_NODE); THEN("the result arrives at the listening node") { - REQUIRE_THAT(listening_node, Equals(niv::testing::AnotherNode())); + REQUIRE_THAT(listening_node, Equals(niv::testing::ANOTHER_NODE)); } } } } WHEN("a node is stored in the shared memory access") { - shared_memory_access.Store(niv::testing::AnyNode()); + shared_memory_access.Store(niv::testing::ANY_NODE); THEN("it can be read from the segment") { REQUIRE_THAT(shared_memory_segment.Read(), - Equals(niv::testing::AnyNode())); + Equals(niv::testing::ANY_NODE)); } GIVEN("a node listening to shared memory") { conduit::Node listening_node{shared_memory_segment.Listen()}; WHEN("the first node is updated and stored again") { - shared_memory_segment.Store(niv::testing::AnotherNode()); + shared_memory_segment.Store(niv::testing::ANOTHER_NODE); THEN("the result arrives at the listening node") { - REQUIRE_THAT(listening_node, Equals(niv::testing::AnotherNode())); + REQUIRE_THAT(listening_node, Equals(niv::testing::ANOTHER_NODE)); } } } @@ -176,13 +176,13 @@ SCENARIO("Overwriting data in shared memory", niv::exchange::SharedMemory::Create()}; niv::exchange::SharedMemory shared_memory_access{ niv::exchange::SharedMemory::Access()}; - shared_memory_segment.Store(niv::testing::AnyNode()); + shared_memory_segment.Store(niv::testing::ANY_NODE); WHEN("when new data is stored in the segment") { - shared_memory_segment.Store(niv::testing::ADifferentNode()); + shared_memory_segment.Store(niv::testing::A_DIFFERENT_NODE); WHEN("that data is read") { conduit::Node read_node{shared_memory_access.Read()}; THEN("the read data is equal to the stored one") { - REQUIRE_THAT(read_node, Equals(niv::testing::ADifferentNode())); + REQUIRE_THAT(read_node, Equals(niv::testing::A_DIFFERENT_NODE)); } } } @@ -199,15 +199,15 @@ SCENARIO("data can be updated in shared memory", niv::exchange::SharedMemory segment{niv::exchange::SharedMemory::Create()}; niv::exchange::SharedMemory segment_access{ niv::exchange::SharedMemory::Access()}; - segment.Store(niv::testing::AnyNode()); + segment.Store(niv::testing::ANY_NODE); WHEN("the data in the shared memory is updated") { - segment.Update(niv::testing::Update()); + segment.Update(niv::testing::ANY_UPDATE); THEN("the updated data can be read from the segment") { - REQUIRE_THAT(segment.Read(), Equals(niv::testing::UpdatedNode())); + REQUIRE_THAT(segment.Read(), Equals(niv::testing::UPDATED_NODE)); } THEN("the updated data can be read from the segment access") { - REQUIRE_THAT(segment.Read(), Equals(niv::testing::UpdatedNode())); + REQUIRE_THAT(segment.Read(), Equals(niv::testing::UPDATED_NODE)); } } segment.Destroy(); diff --git a/niv/tests/src/producer/test_arbor_multimeter.cpp b/niv/tests/src/producer/test_arbor_multimeter.cpp index 2b68569..e8197a2 100644 --- a/niv/tests/src/producer/test_arbor_multimeter.cpp +++ b/niv/tests/src/producer/test_arbor_multimeter.cpp @@ -29,7 +29,7 @@ #include "conduit/conduit.hpp" #include "niv/producer/arbor_multimeter.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/data.hpp" SCENARIO("A multimeter records to a conduit node", "[niv][niv::ArborMultimeter]") { @@ -41,14 +41,14 @@ SCENARIO("A multimeter records to a conduit node", niv::producer::ArborMultimeter::Datum datum{ niv::testing::ANY_TIME + niv::testing::ANY_TIME_OFFSET, niv::testing::ANOTHER_ATTRIBUTE, niv::testing::THIRD_ID_STRING, - niv::testing::ANY_VALUE}; + niv::testing::ANY_DATA_VALUE}; multimeter.Record(datum, &node); THEN("the data is properly recorded") { REQUIRE(node[niv::testing::PathFor(niv::testing::ANY_MULTIMETER_NAME, niv::testing::ANY_TIME_STRING, niv::testing::ANOTHER_ATTRIBUTE, niv::testing::THIRD_ID_STRING)] - .as_double() == Approx(niv::testing::ANY_VALUE)); + .as_double() == Approx(niv::testing::ANY_DATA_VALUE)); } } } diff --git a/niv/tests/src/producer/test_nest_multimeter.cpp b/niv/tests/src/producer/test_nest_multimeter.cpp index 7bbdd4c..67e574f 100644 --- a/niv/tests/src/producer/test_nest_multimeter.cpp +++ b/niv/tests/src/producer/test_nest_multimeter.cpp @@ -28,7 +28,7 @@ #include "conduit/conduit_node.hpp" #include "niv/producer/nest_multimeter.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/data.hpp" SCENARIO("A multimeter records to a conduit node", "[niv][niv::NestMultimeter]") { @@ -39,7 +39,7 @@ SCENARIO("A multimeter records to a conduit node", WHEN("recording data") { niv::producer::NestMultimeter::Datum datum{ niv::testing::ANY_TIME, niv::testing::ANY_ID, - niv::testing::ANY_VALUES_FOR_ATTRIBUTES}; + niv::testing::ANY_DATA_VALUES_FOR_ATTRIBUTES}; multimeter.Record(datum); THEN("data is properly recorded") { REQUIRE(node[niv::testing::PathFor(niv::testing::ANY_MULTIMETER_NAME, diff --git a/niv/tests/src/producer/test_sender.cpp b/niv/tests/src/producer/test_sender.cpp index a064204..a41643e 100644 --- a/niv/tests/src/producer/test_sender.cpp +++ b/niv/tests/src/producer/test_sender.cpp @@ -25,7 +25,7 @@ #include "niv/exchange/relay_shared_memory.hpp" #include "niv/producer/sender.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/helpers.hpp" #include "conduit_node_helper.hpp" @@ -33,7 +33,7 @@ SCENARIO("data is sent via the producer::Sender", "[niv][niv::producer::Sender]") { GIVEN("sender and receiving relay") { niv::producer::Sender sender; - conduit::Node sending_node{niv::testing::AnyNode()}; + conduit::Node sending_node{niv::testing::ANY_NODE}; sender.SetNode(&sending_node); niv::exchange::RelaySharedMemory receiver; @@ -42,7 +42,7 @@ SCENARIO("data is sent via the producer::Sender", conduit::Node received_node = receiver.Receive(); THEN("data is received correctly") { - REQUIRE_THAT(received_node, Equals(niv::testing::AnyNode())); + REQUIRE_THAT(received_node, Equals(niv::testing::ANY_NODE)); } } } diff --git a/niv/tests/src/producer/test_spike_detector.cpp b/niv/tests/src/producer/test_spike_detector.cpp index d64ade4..6168314 100644 --- a/niv/tests/src/producer/test_spike_detector.cpp +++ b/niv/tests/src/producer/test_spike_detector.cpp @@ -27,7 +27,7 @@ #include "conduit/conduit_node.hpp" #include "niv/producer/spike_detector.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/data.hpp" SCENARIO("A spike detector records to a conduit node", "[niv][niv::SpikeDetector]") { diff --git a/niv/tests/src/test_conduit.cpp b/niv/tests/src/test_conduit.cpp index a24c5c1..44ae4f4 100644 --- a/niv/tests/src/test_conduit.cpp +++ b/niv/tests/src/test_conduit.cpp @@ -28,7 +28,8 @@ #include "conduit/conduit_node.hpp" #include "niv/exchange/node_storage.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/conduit_schema.hpp" +#include "niv/testing/helpers.hpp" #include "conduit_node_helper.hpp" @@ -98,7 +99,7 @@ SCENARIO( std::string schema; std::vector bytes; - SerializeConstRef(niv::testing::AnyNode(), &schema, &bytes); + SerializeConstRef(niv::testing::ANY_NODE, &schema, &bytes); conduit::Node second_node; second_node.set_data_using_schema(conduit::Schema(schema), bytes.data()); @@ -109,7 +110,7 @@ SCENARIO( conduit::Node third_node; third_node.set_data_using_schema(conduit::Schema(schema), bytes.data()); - REQUIRE(third_node.to_json() == niv::testing::AnyNode().to_json()); + REQUIRE(third_node.to_json() == niv::testing::ANY_NODE.to_json()); } } } @@ -129,7 +130,7 @@ SCENARIO( std::vector data; niv::exchange::NodeStorage> storage(&schema, &data); - storage.Store(niv::testing::AnyNode()); + storage.Store(niv::testing::ANY_NODE); constexpr bool external{true}; conduit::Node external_node(schema, data.data(), external); @@ -245,14 +246,14 @@ SCENARIO( SCENARIO("update inserts new nodes", "[conduit]") { GIVEN("A conduit tree") { - conduit::Node a = niv::testing::AnyNode(); + conduit::Node a = niv::testing::ANY_NODE; WHEN("A second node updates the tree") { - conduit::Node b = niv::testing::Update(); + conduit::Node b = niv::testing::ANY_UPDATE; a.update(b); THEN("the first node contains also the content of the second") { - REQUIRE_THAT(a, Equals(niv::testing::UpdatedNode())); + REQUIRE_THAT(a, Equals(niv::testing::UPDATED_NODE)); } } } @@ -262,10 +263,10 @@ SCENARIO("node updates into empty node with unexpected order", "[conduit]") { GIVEN("an empty conduit node") { conduit::Node target; WHEN("the target node is updated with some data in unexpected order") { - target.update(niv::testing::Update()); - target.update(niv::testing::AnyNode()); + target.update(niv::testing::ANY_UPDATE); + target.update(niv::testing::ANY_NODE); THEN("the node's layout is unexpected") { - REQUIRE_THAT(target, !Equals(niv::testing::UpdatedNode())); + REQUIRE_THAT(target, !Equals(niv::testing::UPDATED_NODE)); } } } @@ -274,12 +275,12 @@ SCENARIO("node updates into empty node with unexpected order", "[conduit]") { SCENARIO("node updates into pre-allocated node with unexpected order", "[conduit]") { GIVEN("an allocated conduit node") { - conduit::Node preallocated{niv::testing::UpdatedNodeAllZeros()}; + conduit::Node preallocated{niv::testing::UPDATED_NODE_ALL_ZEROS}; WHEN("the node is updated with some data in unexpected order") { - preallocated.update(niv::testing::Update()); - preallocated.update(niv::testing::AnyNode()); + preallocated.update(niv::testing::ANY_UPDATE); + preallocated.update(niv::testing::ANY_NODE); THEN("the node's layout is as expected") { - REQUIRE_THAT(preallocated, Equals(niv::testing::UpdatedNode())); + REQUIRE_THAT(preallocated, Equals(niv::testing::UPDATED_NODE)); } } } @@ -288,7 +289,7 @@ SCENARIO("node updates into pre-allocated node with unexpected order", SCENARIO("conduit data layout", "[conduit]") { GIVEN("a compacted conduit node") { conduit::Node node; - niv::testing::UpdatedNode().compact_to(node); + niv::testing::UPDATED_NODE.compact_to(node); THEN("the node's data is contiguous") { REQUIRE(node.is_contiguous()); } WHEN("the node's data is accessed via ptr") { @@ -296,16 +297,12 @@ SCENARIO("conduit data layout", "[conduit]") { reinterpret_cast(node.contiguous_data_ptr()); THEN("the leafs' data is accessible as an array") { - REQUIRE(data_ptr[0] == - niv::testing::UpdatedNode()["A/B/C"].as_double()); - REQUIRE(data_ptr[1] == - niv::testing::UpdatedNode()["A/B/D"].as_double()); - REQUIRE(data_ptr[2] == - niv::testing::UpdatedNode()["A/B/F"].as_double()); - REQUIRE(data_ptr[3] == - niv::testing::UpdatedNode()["A/B/G"].as_double()); - REQUIRE(data_ptr[4] == niv::testing::UpdatedNode()["A/E"].as_double()); - REQUIRE(data_ptr[5] == niv::testing::UpdatedNode()["A/H"].as_double()); + REQUIRE(data_ptr[0] == niv::testing::UPDATED_NODE["A/B/C"].as_double()); + REQUIRE(data_ptr[1] == niv::testing::UPDATED_NODE["A/B/D"].as_double()); + REQUIRE(data_ptr[2] == niv::testing::UPDATED_NODE["A/B/F"].as_double()); + REQUIRE(data_ptr[3] == niv::testing::UPDATED_NODE["A/B/G"].as_double()); + REQUIRE(data_ptr[4] == niv::testing::UPDATED_NODE["A/E"].as_double()); + REQUIRE(data_ptr[5] == niv::testing::UPDATED_NODE["A/H"].as_double()); } } } @@ -349,17 +346,17 @@ SCENARIO("create conduit::Node from data and schema (stringstream)", GIVEN("a schema and data") { std::stringstream schema; schema << "{\n"; - schema << " " << niv::testing::OpenTag(::ANY_TAG); - schema << " " << niv::testing::OpenTag("B"); - schema << " " << niv::testing::DoubleData(0); - schema << " " << niv::testing::CloseTagNext(); - schema << " " << niv::testing::OpenTag("C"); - schema << " " << niv::testing::DoubleData(8); - schema << " " << niv::testing::CloseTag(); - schema << " " << niv::testing::CloseTagNext(); - schema << " " << niv::testing::OpenTag("D"); - schema << " " << niv::testing::DoubleData(16); - schema << " " << niv::testing::CloseTag(); + schema << " " << niv::testing::conduit_schema::OpenTag(::ANY_TAG); + schema << " " << niv::testing::conduit_schema::OpenTag("B"); + schema << " " << niv::testing::conduit_schema::DoubleData(0); + schema << " " << niv::testing::conduit_schema::CloseTagNext(); + schema << " " << niv::testing::conduit_schema::OpenTag("C"); + schema << " " << niv::testing::conduit_schema::DoubleData(8); + schema << " " << niv::testing::conduit_schema::CloseTag(); + schema << " " << niv::testing::conduit_schema::CloseTagNext(); + schema << " " << niv::testing::conduit_schema::OpenTag("D"); + schema << " " << niv::testing::conduit_schema::DoubleData(16); + schema << " " << niv::testing::conduit_schema::CloseTag(); schema << "}"; std::vector data{1.23, 2.34, 3.45}; diff --git a/pyniv/src/testing/nest_test_data.cpp b/pyniv/src/testing/data.cpp similarity index 78% rename from pyniv/src/testing/nest_test_data.cpp rename to pyniv/src/testing/data.cpp index 8b175e4..d84793c 100644 --- a/pyniv/src/testing/nest_test_data.cpp +++ b/pyniv/src/testing/data.cpp @@ -24,29 +24,12 @@ #include // NOLINT #include // NOLINT -SUPPRESS_WARNINGS_BEGIN -#include "boost/python/numpy.hpp" -SUPPRESS_WARNINGS_END - #include "conduit/conduit_node.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/data.hpp" namespace pyniv { - namespace testing { -bool Equal(const conduit::Node& node1, const conduit::Node& node2) { - bool is_equal = (node1.to_json() == node2.to_json()); - if (!is_equal) { - std::cout << "Nodes are not equal:" << std::endl; - std::cout << "Node 1:" << std::endl; - std::cout << node1.to_json() << std::endl; - std::cout << "----------" << std::endl; - std::cout << "Node 2:" << std::endl; - std::cout << node2.to_json() << std::endl; - } - return is_equal; -} boost::python::list TimeOffsets() { boost::python::list ret_val; @@ -71,7 +54,7 @@ boost::python::list IdOffsets() { #endif template <> -void expose() { +void expose() { EXPOSE_CONSTANT(ANY_DEVICE_NAME); EXPOSE_CONSTANT(NOT_A_DEVICE_NAME); @@ -121,7 +104,7 @@ void expose() { EXPOSE_CONSTANT(ANY_NEST_DATA); - EXPOSE_CONSTANT(ANY_VALUE); + EXPOSE_CONSTANT(ANY_DATA_VALUE); EXPOSE_CONSTANT(TIME_STRIDE); EXPOSE_CONSTANT(ATTRIBUTE_STRIDE); EXPOSE_CONSTANT(ID_STRIDE); @@ -137,13 +120,6 @@ void expose() { def("TIME_OFFSETS", &pyniv::testing::TimeOffsets); def("ID_OFFSETS", &pyniv::testing::IdOffsets); - def("Send", &niv::testing::Send); - def("AnyNode", &niv::testing::AnyNode); - def("AnotherNode", &niv::testing::AnotherNode); - def("Update", &niv::testing::Update); - def("UpdatedNode", &niv::testing::UpdatedNode); - def("ADifferentNode", &niv::testing::ADifferentNode); - def("Equal", &pyniv::testing::Equal); def("ValueAt", &niv::testing::ValueAt); } diff --git a/pyniv/src/testing/helpers.cpp b/pyniv/src/testing/helpers.cpp new file mode 100644 index 0000000..446b84c --- /dev/null +++ b/pyniv/src/testing/helpers.cpp @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017-2018 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// 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 "pyniv.hpp" + +#include // NOLINT +#include // NOLINT + +#include "conduit/conduit_node.hpp" + +#include "niv/testing/helpers.hpp" + +namespace pyniv { +namespace testing { + +bool Equal(const conduit::Node& node1, const conduit::Node& node2) { + bool is_equal = (node1.to_json() == node2.to_json()); + if (!is_equal) { + std::cout << "Nodes are not equal:" << std::endl; + std::cout << "Node 1:" << std::endl; + std::cout << node1.to_json() << std::endl; + std::cout << "----------" << std::endl; + std::cout << "Node 2:" << std::endl; + std::cout << node2.to_json() << std::endl; + } + return is_equal; +} + +} // namespace testing + +#ifndef EXPOSE_CONSTANT +#define EXPOSE_CONSTANT(a) scope().attr(#a) = niv::testing::a +#endif + +template <> +void expose() { + EXPOSE_CONSTANT(ANY_NODE); + EXPOSE_CONSTANT(ANOTHER_NODE); + EXPOSE_CONSTANT(ANY_UPDATE); + EXPOSE_CONSTANT(UPDATED_NODE); + EXPOSE_CONSTANT(A_DIFFERENT_NODE); + + def("Send", &niv::testing::Send); + def("Equal", &pyniv::testing::Equal); +} + +} // namespace pyniv diff --git a/pyniv/src/testing/testing.cpp b/pyniv/src/testing/testing.cpp index 61a98b3..d5a584a 100644 --- a/pyniv/src/testing/testing.cpp +++ b/pyniv/src/testing/testing.cpp @@ -21,10 +21,14 @@ #include "pyniv.hpp" -#include "niv/testing/nest_test_data.hpp" +#include "niv/testing/data.hpp" +#include "niv/testing/helpers.hpp" namespace pyniv { -BOOST_PYTHON_MODULE(_testing) { pyniv::expose(); } +BOOST_PYTHON_MODULE(_testing) { + pyniv::expose(); + pyniv::expose(); +} } // namespace pyniv diff --git a/pyniv/tests/src/consumer/test_receiver.py b/pyniv/tests/src/consumer/test_receiver.py index 4945d36..69653c6 100644 --- a/pyniv/tests/src/consumer/test_receiver.py +++ b/pyniv/tests/src/consumer/test_receiver.py @@ -26,12 +26,12 @@ def test_receiver_aggregates_data(): receiving_node = pyniv.conduit.Node() receiver.SetNode(receiving_node) - pyniv.testing.Send(pyniv.testing.AnyNode()) + pyniv.testing.Send(pyniv.testing.ANY_NODE) receiver.Receive() - assert pyniv.testing.Equal(receiving_node, pyniv.testing.AnyNode()) + assert pyniv.testing.Equal(receiving_node, pyniv.testing.ANY_NODE) - pyniv.testing.Send(pyniv.testing.Update()) + pyniv.testing.Send(pyniv.testing.ANY_UPDATE) receiver.Receive() - assert pyniv.testing.Equal(receiving_node, pyniv.testing.UpdatedNode()) + assert pyniv.testing.Equal(receiving_node, pyniv.testing.UPDATED_NODE)