File: test_serialization.cpp

package info (click to toggle)
opentimelineio 0.18.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 23,480 kB
  • sloc: cpp: 163,182; python: 50,821; ansic: 6,470; makefile: 1,091; sh: 892; xml: 182; javascript: 2
file content (120 lines) | stat: -rw-r--r-- 3,859 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// 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,
        "color": null,
        "children": [
            {
                "OTIO_SCHEMA": "Track.1",
                "metadata": {},
                "name": "",
                "source_range": null,
                "effects": [],
                "markers": [],
                "enabled": true,
                "color": null,
                "children": [
                    {
                        "OTIO_SCHEMA": "Clip.2",
                        "metadata": {},
                        "name": "",
                        "source_range": null,
                        "effects": [],
                        "markers": [],
                        "enabled": true,
                        "color": null,
                        "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;
}