6
6
7
7
#include " astronomy/time_scales.hpp"
8
8
#include " astronomy/mercury_orbiter.hpp"
9
+ #include " base/array.hpp"
9
10
#include " base/file.hpp"
10
11
#include " base/not_null.hpp"
11
12
#include " base/pull_serializer.hpp"
12
13
#include " base/push_deserializer.hpp"
14
+ #include " base/serialization.hpp"
13
15
#include " glog/logging.h"
14
16
#include " gmock/gmock.h"
15
17
#include " gtest/gtest.h"
18
+ #include " ksp_plugin/frames.hpp"
16
19
#include " ksp_plugin/interface.hpp"
17
20
#include " ksp_plugin/plugin.hpp"
21
+ #include " physics/discrete_trajectory.hpp"
18
22
#include " serialization/ksp_plugin.pb.h"
19
23
#include " testing_utilities/is_near.hpp"
20
24
#include " testing_utilities/serialization.hpp"
@@ -30,15 +34,20 @@ using astronomy::date_time::DateTime;
30
34
using astronomy::date_time::operator " " _DateTime;
31
35
using base::not_null;
32
36
using base::OFStream;
37
+ using base::ParseFromBytes;
33
38
using base::PullSerializer;
34
39
using base::PushDeserializer;
40
+ using ksp_plugin::Barycentric;
35
41
using ksp_plugin::Plugin;
42
+ using physics::DiscreteTrajectory;
36
43
using quantities::Speed;
37
44
using quantities::si::Kilo;
38
45
using testing_utilities::operator " " _⑴;
39
46
using testing_utilities::IsNear;
47
+ using testing_utilities::ReadFromBinaryFile;
40
48
using testing_utilities::ReadLinesFromBase64File;
41
49
using testing_utilities::ReadLinesFromHexadecimalFile;
50
+ using testing_utilities::WriteToBinaryFile;
42
51
using ::testing::AllOf;
43
52
using ::testing::ElementsAre;
44
53
using ::testing::Eq;
@@ -287,10 +296,8 @@ TEST_F(PluginCompatibilityTest, DISABLED_Butcher) {
287
296
R"( P:\Public Mockingbird\Principia\Saves\1119\1119.proto.b64)" ,
288
297
/* compressor=*/ " gipfeli" ,
289
298
/* decoder=*/ " base64" );
290
- // TODO(phl): Check that we mention a compatibility path here once something
291
- // changes.
292
299
EXPECT_THAT (log_warning.string (),
293
- Not (HasSubstr (" pre-Gröbner" )));
300
+ AllOf ( HasSubstr ( " pre-Haar " ), Not (HasSubstr (" pre-Gröbner" ) )));
294
301
auto const & orbiter =
295
302
*plugin->GetVessel (" e180ca12-492f-45bf-a194-4c5255aec8a0" );
296
303
EXPECT_THAT (orbiter.name (), Eq (" Mercury Orbiter 1" ));
@@ -348,6 +355,51 @@ TEST_F(PluginCompatibilityTest, DISABLED_Butcher) {
348
355
WriteAndReadBack (std::move (plugin));
349
356
}
350
357
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
+ }
351
403
352
404
// Use for debugging saves given by users.
353
405
TEST_F (PluginCompatibilityTest, DISABLED_SECULAR_Debug) {
0 commit comments