-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make serialize_json_to_string output compactly (without newlines) whe…
…n indent argument is less than 1 (#1578) * Make serialize_json_to_string output compact when indent is less than 1 * Add C++ test --------- Signed-off-by: Jean-Christophe Morin <[email protected]>
- Loading branch information
1 parent
6f4ed5e
commit 23ff3f9
Showing
3 changed files
with
171 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Contributors to the OpenTimelineIO project | ||
|
||
#include "utils.h" | ||
|
||
#include <opentimelineio/clip.h> | ||
#include <opentimelineio/timeline.h> | ||
#include <opentimelineio/track.h> | ||
#include <opentimelineio/serialization.h> | ||
#include <opentimelineio/serializableObject.h> | ||
#include <opentimelineio/serializableObjectWithMetadata.h> | ||
#include <opentimelineio/safely_typed_any.h> | ||
|
||
#include <iostream> | ||
#include <string> | ||
|
||
namespace otime = opentime::OPENTIME_VERSION; | ||
namespace otio = opentimelineio::OPENTIMELINEIO_VERSION; | ||
|
||
int | ||
main(int argc, char** argv) | ||
{ | ||
Tests tests; | ||
|
||
tests.add_test( | ||
"success with default indent", [] { | ||
otio::SerializableObject::Retainer<otio::Clip> cl = | ||
new otio::Clip(); | ||
otio::SerializableObject::Retainer<otio::Track> tr = | ||
new otio::Track(); | ||
tr->append_child(cl); | ||
otio::SerializableObject::Retainer<otio::Timeline> tl = | ||
new otio::Timeline(); | ||
tl->tracks()->append_child(tr); | ||
|
||
otio::ErrorStatus err; | ||
auto output = tl.value->to_json_string(&err, {}); | ||
assertFalse(otio::is_error(err)); | ||
assertEqual(output.c_str(), R"CONTENT({ | ||
"OTIO_SCHEMA": "Timeline.1", | ||
"metadata": {}, | ||
"name": "", | ||
"global_start_time": null, | ||
"tracks": { | ||
"OTIO_SCHEMA": "Stack.1", | ||
"metadata": {}, | ||
"name": "tracks", | ||
"source_range": null, | ||
"effects": [], | ||
"markers": [], | ||
"enabled": true, | ||
"children": [ | ||
{ | ||
"OTIO_SCHEMA": "Track.1", | ||
"metadata": {}, | ||
"name": "", | ||
"source_range": null, | ||
"effects": [], | ||
"markers": [], | ||
"enabled": true, | ||
"children": [ | ||
{ | ||
"OTIO_SCHEMA": "Clip.2", | ||
"metadata": {}, | ||
"name": "", | ||
"source_range": null, | ||
"effects": [], | ||
"markers": [], | ||
"enabled": true, | ||
"media_references": { | ||
"DEFAULT_MEDIA": { | ||
"OTIO_SCHEMA": "MissingReference.1", | ||
"metadata": {}, | ||
"name": "", | ||
"available_range": null, | ||
"available_image_bounds": null | ||
} | ||
}, | ||
"active_media_reference_key": "DEFAULT_MEDIA" | ||
} | ||
], | ||
"kind": "Video" | ||
} | ||
] | ||
} | ||
})CONTENT"); | ||
}); | ||
|
||
tests.add_test( | ||
"success with indent set to 0", [] { | ||
otio::SerializableObject::Retainer<otio::SerializableObjectWithMetadata> so = | ||
new otio::SerializableObjectWithMetadata(); | ||
|
||
otio::ErrorStatus err; | ||
auto output = so.value->to_json_string(&err, {}, 0); | ||
assertFalse(otio::is_error(err)); | ||
assertEqual(output.c_str(), R"CONTENT({"OTIO_SCHEMA":"SerializableObjectWithMetadata.1","metadata":{},"name":""})CONTENT"); | ||
}); | ||
|
||
tests.add_test( | ||
"success with indent set to 2", [] { | ||
otio::SerializableObject::Retainer<otio::SerializableObjectWithMetadata> so = | ||
new otio::SerializableObjectWithMetadata(); | ||
|
||
otio::ErrorStatus err; | ||
auto output = so.value->to_json_string(&err, {}, 2); | ||
assertFalse(otio::is_error(err)); | ||
assertEqual(output.c_str(), R"CONTENT({ | ||
"OTIO_SCHEMA": "SerializableObjectWithMetadata.1", | ||
"metadata": {}, | ||
"name": "" | ||
})CONTENT"); | ||
}); | ||
|
||
tests.run(argc, argv); | ||
return 0; | ||
} |