File: dbus_api_stability.rs

package info (click to toggle)
glycin 1.2.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 11,868 kB
  • sloc: python: 257; ansic: 93; xml: 44; makefile: 28; sh: 21; javascript: 10
file content (138 lines) | stat: -rw-r--r-- 3,726 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use std::os::unix::net::UnixStream;
use std::sync::Mutex;

#[test]
#[ignore]
fn dbus_api_stability() {
    // TODO: This seems overly complicated
    blocking::unblock(|| async_io::block_on(start_dbus())).detach();
    check_api_stability("org.gnome.glycin.Loader");
    check_api_stability("org.gnome.glycin.Editor");
}

fn check_api_stability(interface_name: &str) {
    let output = std::process::Command::new("busctl")
        .args([
            "introspect",
            "--user",
            "--xml-interface",
            "org.gnome.glycin.Test",
            "/org/gnome/glycin/test",
        ])
        .output()
        .unwrap();

    let compat_version = glycin::COMPAT_VERSION;
    let current_api =
        std::fs::read_to_string(format!("../docs/{compat_version}+/{interface_name}.xml")).unwrap();

    let s = r#"<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
  "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
"#
    .to_string();

    let mut api = String::from_utf8(output.stdout)
        .unwrap()
        .lines()
        .fold((false, s), |(mut take, mut s), line| {
            if line.contains(interface_name) {
                take = true;
            }

            if take {
                s.push_str(line);
                s.push('\n');
            }

            if line.contains("</interface>") {
                take = false;
            }

            (take, s)
        })
        .1;

    api.push_str("</node>\n");

    if current_api != api {
        eprintln!("{api}");
    }

    assert_eq!(api, current_api);
}

async fn start_dbus() {
    let _connection = zbus::connection::Builder::session()
        .unwrap()
        .name("org.gnome.glycin.Test")
        .unwrap()
        .serve_at("/org/gnome/glycin/test", mock_loader())
        .unwrap()
        .serve_at("/org/gnome/glycin/test", mock_editor())
        .unwrap()
        .build()
        .await
        .unwrap();

    std::future::pending::<()>().await;
}

fn mock_loader() -> glycin_utils::Loader {
    struct MockLoader {}

    impl glycin_utils::LoaderImplementation for MockLoader {
        fn init(
            &self,
            _stream: UnixStream,
            _mime_type: String,
            _details: glycin_utils::InitializationDetails,
        ) -> Result<glycin_utils::ImageInfo, glycin_utils::ProcessError> {
            unimplemented!()
        }
        fn frame(
            &self,
            _frame_request: glycin_utils::FrameRequest,
        ) -> Result<glycin_utils::Frame, glycin_utils::ProcessError> {
            unimplemented!()
        }
    }

    let loader_impl = MockLoader {};

    glycin_utils::Loader {
        loader: Mutex::new(Box::new(loader_impl)),
    }
}

fn mock_editor() -> glycin_utils::Editor {
    struct MockEditor {}

    impl glycin_utils::EditorImplementation for MockEditor {
        fn apply_sparse(
            &self,
            _stream: UnixStream,
            _mime_type: String,
            _details: glycin_utils::InitializationDetails,
            _operations: glycin_utils::operations::Operations,
        ) -> Result<glycin_utils::SparseEditorOutput, glycin_utils::ProcessError> {
            unimplemented!()
        }

        fn apply_complete(
            &self,
            _stream: UnixStream,
            _mime_type: String,
            _details: glycin_utils::InitializationDetails,
            _operations: glycin_utils::operations::Operations,
        ) -> Result<glycin_utils::CompleteEditorOutput, glycin_utils::ProcessError> {
            unimplemented!()
        }
    }

    let editor_impl = MockEditor {};

    glycin_utils::Editor {
        editor: Mutex::new(Box::new(editor_impl)),
    }
}