Skip to content

Commit 8841754

Browse files
authored
Merge pull request #3159 from pleroy/Lpg
A test to produce a pre-Ζήνων trajectory
2 parents 17b20a6 + 5acb7ea commit 8841754

File tree

2 files changed

+59
-5
lines changed

2 files changed

+59
-5
lines changed

ksp_plugin_test/plugin_compatibility_test.cpp

+55-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66

77
#include "astronomy/time_scales.hpp"
88
#include "astronomy/mercury_orbiter.hpp"
9+
#include "base/array.hpp"
910
#include "base/file.hpp"
1011
#include "base/not_null.hpp"
1112
#include "base/pull_serializer.hpp"
1213
#include "base/push_deserializer.hpp"
14+
#include "base/serialization.hpp"
1315
#include "glog/logging.h"
1416
#include "gmock/gmock.h"
1517
#include "gtest/gtest.h"
18+
#include "ksp_plugin/frames.hpp"
1619
#include "ksp_plugin/interface.hpp"
1720
#include "ksp_plugin/plugin.hpp"
21+
#include "physics/discrete_trajectory.hpp"
1822
#include "serialization/ksp_plugin.pb.h"
1923
#include "testing_utilities/is_near.hpp"
2024
#include "testing_utilities/serialization.hpp"
@@ -30,15 +34,20 @@ using astronomy::date_time::DateTime;
3034
using astronomy::date_time::operator""_DateTime;
3135
using base::not_null;
3236
using base::OFStream;
37+
using base::ParseFromBytes;
3338
using base::PullSerializer;
3439
using base::PushDeserializer;
40+
using ksp_plugin::Barycentric;
3541
using ksp_plugin::Plugin;
42+
using physics::DiscreteTrajectory;
3643
using quantities::Speed;
3744
using quantities::si::Kilo;
3845
using testing_utilities::operator""_⑴;
3946
using testing_utilities::IsNear;
47+
using testing_utilities::ReadFromBinaryFile;
4048
using testing_utilities::ReadLinesFromBase64File;
4149
using testing_utilities::ReadLinesFromHexadecimalFile;
50+
using testing_utilities::WriteToBinaryFile;
4251
using ::testing::AllOf;
4352
using ::testing::ElementsAre;
4453
using ::testing::Eq;
@@ -287,10 +296,8 @@ TEST_F(PluginCompatibilityTest, DISABLED_Butcher) {
287296
R"(P:\Public Mockingbird\Principia\Saves\1119\1119.proto.b64)",
288297
/*compressor=*/"gipfeli",
289298
/*decoder=*/"base64");
290-
// TODO(phl): Check that we mention a compatibility path here once something
291-
// changes.
292299
EXPECT_THAT(log_warning.string(),
293-
Not(HasSubstr("pre-Gröbner")));
300+
AllOf(HasSubstr("pre-Haar"), Not(HasSubstr("pre-Gröbner"))));
294301
auto const& orbiter =
295302
*plugin->GetVessel("e180ca12-492f-45bf-a194-4c5255aec8a0");
296303
EXPECT_THAT(orbiter.name(), Eq("Mercury Orbiter 1"));
@@ -348,6 +355,51 @@ TEST_F(PluginCompatibilityTest, DISABLED_Butcher) {
348355
WriteAndReadBack(std::move(plugin));
349356
}
350357

358+
TEST_F(PluginCompatibilityTest, DISABLED_Lpg) {
359+
StringLogSink log_warning(google::WARNING);
360+
not_null<std::unique_ptr<Plugin const>> plugin = ReadPluginFromFile(
361+
R"(P:\Public Mockingbird\Principia\Saves\3136\3136.proto.b64)",
362+
/*compressor=*/"gipfeli",
363+
/*decoder=*/"base64");
364+
// TODO(phl): Check that we mention a compatibility path here once something
365+
// changes.
366+
EXPECT_THAT(log_warning.string(),
367+
Not(HasSubstr("pre-Haar")));
368+
369+
// The vessel with the longest history.
370+
auto const& vessel =
371+
*plugin->GetVessel("77ddea45-47ee-48c0-aee9-d55cdb35ffcd");
372+
auto& psychohistory =
373+
const_cast<DiscreteTrajectory<Barycentric>&>(vessel.psychohistory());
374+
auto const history = psychohistory.root();
375+
EXPECT_EQ(435'927, history->Size());
376+
EXPECT_EQ(435'929, psychohistory.Size());
377+
378+
// Serialize the history and psychohistory to a temporary file.
379+
{
380+
serialization::DiscreteTrajectory message;
381+
history->WriteToMessage(&message, /*forks=*/{&psychohistory}, /*exact=*/{});
382+
auto const serialized_message = base::SerializeAsBytes(message);
383+
WriteToBinaryFile(TEMP_DIR / "trajectory_3136.proto.bin",
384+
serialized_message.get());
385+
}
386+
387+
// Deserialize the temporary file to make sure that it's valid.
388+
{
389+
auto const serialized_message =
390+
ReadFromBinaryFile(TEMP_DIR / "trajectory_3136.proto.bin");
391+
auto const message =
392+
ParseFromBytes<serialization::DiscreteTrajectory>(serialized_message);
393+
DiscreteTrajectory<Barycentric>* psychohistory = nullptr;
394+
auto const history = DiscreteTrajectory<Barycentric>::ReadFromMessage(
395+
message, /*forks=*/{&psychohistory});
396+
EXPECT_EQ(435'927, history->Size());
397+
EXPECT_EQ(435'929, psychohistory->Size());
398+
}
399+
400+
// Make sure that we can upgrade, save, and reload.
401+
WriteAndReadBack(std::move(plugin));
402+
}
351403

352404
// Use for debugging saves given by users.
353405
TEST_F(PluginCompatibilityTest, DISABLED_SECULAR_Debug) {

physics/discrete_trajectory_body.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,12 @@ typename DiscreteTrajectory<Frame>::Downsampling
486486
DiscreteTrajectory<Frame>::Downsampling::ReadFromMessage(
487487
serialization::DiscreteTrajectory::Downsampling const& message,
488488
Timeline const& timeline) {
489-
bool const is_pre_grotendieck_haar = message.has_start_of_dense_timeline();
489+
bool const is_pre_haar = message.has_start_of_dense_timeline();
490+
LOG_IF(WARNING, is_pre_haar)
491+
<< "Reading pre-Haar DiscreteTrajectory.Downsampling";
490492
Downsampling downsampling({message.max_dense_intervals(),
491493
Length::ReadFromMessage(message.tolerance())});
492-
if (is_pre_grotendieck_haar) {
494+
if (is_pre_haar) {
493495
// No support for forks in legacy saves, so |find| will succeed and ++ is
494496
// safe.
495497
auto it = timeline.find(

0 commit comments

Comments
 (0)