autosar_data_abstraction/software_component/
connector.rs

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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
use crate::{abstraction_element, software_component, AbstractionElement, AutosarAbstractionError};
use autosar_data::{Element, ElementName};
use software_component::{PortInterface, PortPrototype, SwComponentPrototype};

//#########################################################

/// A `DelegationSwConnector` connects a port of a software component that is contained inside a `SwCompositionType` with a port of the `SwCompositionType`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct DelegationSwConnector(Element);
abstraction_element!(DelegationSwConnector, DelegationSwConnector);

impl DelegationSwConnector {
    /// Create a new `DelegationSwConnector`
    ///
    /// # Arguments
    /// `inner_port`: A port of a software component that is contained inside the `SwCompositionType`.
    /// `outer_port`: A port of the `SwCompositionType`.
    pub(crate) fn new(
        name: &str,
        parent_element: &Element,
        inner_port: &PortPrototype,
        inner_sw_prototype: &SwComponentPrototype,
        outer_port: &PortPrototype,
    ) -> Result<Self, AutosarAbstractionError> {
        let inner_port_interface = inner_port.port_interface()?;
        // the caller (CompositionSwComponentType::add_connector) ensures that the inner and outer port both have the same kind of interface
        match &inner_port_interface {
            PortInterface::SenderReceiverInterface(_) | PortInterface::NvDataInterface(_) => {
                if (matches!(inner_port, PortPrototype::R(_)) && matches!(outer_port, PortPrototype::P(_)))
                    || (matches!(inner_port, PortPrototype::P(_)) && matches!(outer_port, PortPrototype::R(_)))
                {
                    return Err(AutosarAbstractionError::InvalidParameter(
                        "Invalid combination of provide and require ports".to_string(),
                    ));
                }
            }
            PortInterface::ClientServerInterface(_)
            | PortInterface::ModeSwitchInterface(_)
            | PortInterface::TriggerInterface(_) => {
                // table of valid combinations; Table 4.14 in AUTOSAR_TPS_SoftwareComponentTemplate.pdf:
                // inner_port\outer_port | P   | R   | PR
                // P                     | yes | no  | no
                // R                     | no  | yes | no
                // PR                    | no  | yes | no
                match (inner_port, outer_port) {
                    (PortPrototype::P(_) | PortPrototype::PR(_), PortPrototype::P(_))
                    | (PortPrototype::R(_), PortPrototype::R(_)) => {}
                    _ => {
                        return Err(AutosarAbstractionError::InvalidParameter(
                            "Invalid combination of provide and require ports".to_string(),
                        ));
                    }
                }
            }
            PortInterface::ParameterInterface(_) => { /* no specific restrictions on ParameterInterfaces */ }
        }

        let delegation_sw_connector =
            parent_element.create_named_sub_element(ElementName::DelegationSwConnector, name)?;
        let inner_iref = delegation_sw_connector.create_sub_element(ElementName::InnerPortIref)?;
        // let inner_swc = SwComponentType::try_from(inner_port.element().named_parent()?.unwrap())?;
        // The inner port is either described by an RPortInCompositionInstanceRef or a PPortInCompositionInstanceRef, depending on the port type.
        // If the inner port is a PRPortPrototype, the inner port is described by an PPortInCompositionInstanceRef, as required by [TPS_SWCT_01515].
        if matches!(inner_port, PortPrototype::R(_)) {
            // inner port is a required port
            let r_port_in_instance = inner_iref.create_sub_element(ElementName::RPortInCompositionInstanceRef)?;
            r_port_in_instance
                .create_sub_element(ElementName::TargetRPortRef)?
                .set_reference_target(inner_port.element())?;
            r_port_in_instance
                .create_sub_element(ElementName::ContextComponentRef)?
                .set_reference_target(inner_sw_prototype.element())?;
        } else {
            // inner port is a provided port or a PR port
            let p_port_in_instance = inner_iref.create_sub_element(ElementName::PPortInCompositionInstanceRef)?;
            p_port_in_instance
                .create_sub_element(ElementName::TargetPPortRef)?
                .set_reference_target(inner_port.element())?;
            p_port_in_instance
                .create_sub_element(ElementName::ContextComponentRef)?
                .set_reference_target(inner_sw_prototype.element())?;
        };
        delegation_sw_connector
            .create_sub_element(ElementName::OuterPortRef)?
            .set_reference_target(outer_port.element())?;

        Ok(Self(delegation_sw_connector))
    }
}

//##################################################################

/// An `AssemblySwConnector` connects ports of two `SwCompositionType`s.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AssemblySwConnector(Element);
abstraction_element!(AssemblySwConnector, AssemblySwConnector);

impl AssemblySwConnector {
    /// Create a new `AssemblySwConnector`
    pub(crate) fn new(
        name: &str,
        parent_element: &Element,
        port_1: &PortPrototype,
        sw_prototype_1: &SwComponentPrototype,
        port_2: &PortPrototype,
        sw_prototype_2: &SwComponentPrototype,
    ) -> Result<Self, AutosarAbstractionError> {
        // find the provider and requester port; also filter out invalid combinations such as P-P and R-R
        let (provider, p_proto_swc, requester, r_proto_swc) = match (port_1, port_2) {
            (PortPrototype::P(_), PortPrototype::R(_)) => (port_1, sw_prototype_1, port_2, sw_prototype_2),
            (PortPrototype::R(_), PortPrototype::P(_)) => (port_2, sw_prototype_2, port_1, sw_prototype_1),
            (PortPrototype::P(_), PortPrototype::PR(_)) => (port_1, sw_prototype_1, port_2, sw_prototype_2),
            (PortPrototype::PR(_), PortPrototype::P(_)) => (port_2, sw_prototype_2, port_1, sw_prototype_1),
            (PortPrototype::R(_), PortPrototype::PR(_)) => (port_2, sw_prototype_2, port_1, sw_prototype_1),
            (PortPrototype::PR(_), PortPrototype::R(_)) => (port_1, sw_prototype_1, port_2, sw_prototype_2),
            (PortPrototype::PR(_), PortPrototype::PR(_)) => (port_1, sw_prototype_1, port_2, sw_prototype_2),
            _ => {
                return Err(AutosarAbstractionError::InvalidParameter(
                    "Invalid port roles".to_string(),
                ))
            }
        };

        let port_interface = provider.port_interface()?;
        // additional restrictions beyond the basic rules in the match above
        // apply to ClientServer, ModeSwitch, and Trigger interfaces
        if matches!(
            &port_interface,
            PortInterface::ClientServerInterface(_)
                | PortInterface::ModeSwitchInterface(_)
                | PortInterface::TriggerInterface(_)
        ) {
            // can only connect R to P or PR. All other combinations are forbidden.
            // As a result of the match above, we know that provider is P or PR and requester is R or PR.
            if !matches!(requester, PortPrototype::R(_)) {
                return Err(AutosarAbstractionError::InvalidParameter(
                    "Invalid combination of provide and require ports".to_string(),
                ));
            }
        }

        let assembly_sw_connector = parent_element.create_named_sub_element(ElementName::AssemblySwConnector, name)?;

        let provider_iref = assembly_sw_connector.create_sub_element(ElementName::ProviderIref)?;
        provider_iref
            .create_sub_element(ElementName::TargetPPortRef)?
            .set_reference_target(provider.element())?;
        provider_iref
            .create_sub_element(ElementName::ContextComponentRef)?
            .set_reference_target(p_proto_swc.element())?;
        let requester_iref = assembly_sw_connector.create_sub_element(ElementName::RequesterIref)?;
        requester_iref
            .create_sub_element(ElementName::TargetRPortRef)?
            .set_reference_target(requester.element())?;
        requester_iref
            .create_sub_element(ElementName::ContextComponentRef)?
            .set_reference_target(r_proto_swc.element())?;

        Ok(Self(assembly_sw_connector))
    }
}

//##################################################################

/// A `PassThroughSwConnector` connects two ports of a `SwCompositionType`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PassThroughSwConnector(Element);
abstraction_element!(PassThroughSwConnector, PassThroughSwConnector);

impl PassThroughSwConnector {
    /// Create a new `PassThroughSwConnector`
    pub(crate) fn new(
        name: &str,
        parent_element: &Element,
        port_1: &PortPrototype,
        port_2: &PortPrototype,
    ) -> Result<Self, AutosarAbstractionError> {
        let (provided_port, required_port) = match (&port_1, &port_2) {
            (PortPrototype::P(_), PortPrototype::R(_)) => (port_1, port_2),
            (PortPrototype::R(_), PortPrototype::P(_)) => (port_2, port_1),
            (PortPrototype::P(_), PortPrototype::PR(_)) => (port_1, port_2),
            (PortPrototype::PR(_), PortPrototype::P(_)) => (port_2, port_1),
            (PortPrototype::R(_), PortPrototype::PR(_)) => (port_2, port_1),
            (PortPrototype::PR(_), PortPrototype::R(_)) => (port_1, port_2),
            (PortPrototype::PR(_), PortPrototype::PR(_)) => (port_1, port_2),
            _ => {
                return Err(AutosarAbstractionError::InvalidParameter(
                    "Invalid port roles".to_string(),
                ))
            }
        };

        let pass_through_sw_connector =
            parent_element.create_named_sub_element(ElementName::PassThroughSwConnector, name)?;

        pass_through_sw_connector
            .create_sub_element(ElementName::ProvidedOuterPortRef)?
            .set_reference_target(provided_port.element())?;
        pass_through_sw_connector
            .create_sub_element(ElementName::RequiredOuterPortRef)?
            .set_reference_target(required_port.element())?;

        Ok(Self(pass_through_sw_connector))
    }
}

//##################################################################

/// A `SwConnector` is a generic enum that can represent any kind of software connector.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SwConnector {
    /// The connector is a `DelegationSwConnector`
    Delegation(DelegationSwConnector),
    /// The connector is an `AssemblySwConnector`
    Assembly(AssemblySwConnector),
    /// The connector is a `PassThroughSwConnector`
    PassThrough(PassThroughSwConnector),
}

impl AbstractionElement for SwConnector {
    fn element(&self) -> &Element {
        match self {
            SwConnector::Delegation(connector) => connector.element(),
            SwConnector::Assembly(connector) => connector.element(),
            SwConnector::PassThrough(connector) => connector.element(),
        }
    }
}

impl TryFrom<Element> for SwConnector {
    type Error = AutosarAbstractionError;

    fn try_from(element: Element) -> Result<Self, Self::Error> {
        match element.element_name() {
            ElementName::DelegationSwConnector => Ok(SwConnector::Delegation(DelegationSwConnector(element))),
            ElementName::AssemblySwConnector => Ok(SwConnector::Assembly(AssemblySwConnector(element))),
            ElementName::PassThroughSwConnector => Ok(SwConnector::PassThrough(PassThroughSwConnector(element))),
            _ => Err(AutosarAbstractionError::ConversionError {
                element: element.clone(),
                dest: "SwConnector".to_string(),
            }),
        }
    }
}

//##################################################################

#[cfg(test)]
mod test {
    use super::*;
    use crate::ArPackage;
    use autosar_data::{AutosarModel, AutosarVersion, ElementName};
    use software_component::{
        AbstractSwComponentType, ApplicationSwComponentType, ClientServerInterface, CompositionSwComponentType,
        SenderReceiverInterface,
    };

    #[test]
    fn test_delegation_sw_connector() {
        let model = AutosarModel::new();
        let _file = model.create_file("filename", AutosarVersion::LATEST).unwrap();
        let package = ArPackage::get_or_create(&model, "/package").unwrap();

        // create interfaces for the ports
        let sr_interface = package.create_sender_receiver_interface("sr_interface").unwrap();
        let cs_interface = package.create_client_server_interface("cs_interface").unwrap();

        // create a composition and an application sw component type
        let composition = package.create_composition_sw_component_type("composition").unwrap();
        let swc_type = package.create_application_sw_component_type("app_type").unwrap();

        // create multiple ports with different interfaces and directions
        let outer_sr_p_port = composition.create_p_port("outer_sr_p_port", &sr_interface).unwrap();
        let inner_sr_p_port = swc_type.create_p_port("inner_sr_p_port", &sr_interface).unwrap();
        let outer_sr_r_port = composition.create_r_port("outer_sr_r_port", &sr_interface).unwrap();
        let inner_sr_r_port = swc_type.create_r_port("inner_sr_r_port", &sr_interface).unwrap();
        let outer_sr_pr_port = composition.create_pr_port("outer_sr_pr_port", &sr_interface).unwrap();
        let inner_sr_pr_port = swc_type.create_pr_port("inner_sr_pr_port", &sr_interface).unwrap();

        let outer_cs_p_port = composition.create_p_port("outer_cs_p_port", &cs_interface).unwrap();
        let inner_cs_p_port = swc_type.create_p_port("inner_cs_p_port", &cs_interface).unwrap();
        let outer_cs_r_port = composition.create_r_port("outer_cs_r_port", &cs_interface).unwrap();
        let inner_cs_r_port = swc_type.create_r_port("inner_cs_r_port", &cs_interface).unwrap();
        let outer_cs_pr_port = composition.create_pr_port("outer_cs_pr_port", &cs_interface).unwrap();
        let inner_cs_pr_port = swc_type.create_pr_port("inner_cs_pr_port", &cs_interface).unwrap();

        // add the application sw component type to the composition
        let app_prototype = composition.create_component("app_prototype", &swc_type).unwrap();

        // connect the outer port of the composition with the inner port of the application sw component type
        let sr_p_connector = composition
            .create_delegation_connector("sr_p_connector", &inner_sr_p_port, &app_prototype, &outer_sr_p_port)
            .unwrap();
        let _sr_r_connector = composition
            .create_delegation_connector("sr_r_connector", &inner_sr_r_port, &app_prototype, &outer_sr_r_port)
            .unwrap();
        let _sr_pr_connector = composition
            .create_delegation_connector("sr_pr_connector", &inner_sr_pr_port, &app_prototype, &outer_sr_pr_port)
            .unwrap();
        let _cs_p_connector = composition
            .create_delegation_connector("cs_p_connector", &inner_cs_p_port, &app_prototype, &outer_cs_p_port)
            .unwrap();
        let _cs_r_connector = composition
            .create_delegation_connector("cs_r_connector", &inner_cs_r_port, &app_prototype, &outer_cs_r_port)
            .unwrap();
        // connecting a PR port to a PR port is not allowed for ClientServerInterfaces
        let cs_pr_connector_result = composition.create_delegation_connector(
            "cs_pr_connector",
            &inner_cs_pr_port,
            &app_prototype,
            &outer_cs_pr_port,
        );
        assert!(cs_pr_connector_result.is_err());

        // connecting different interfaces is not allowed
        let result = composition.create_delegation_connector(
            "invalid_connector",
            &inner_sr_p_port,
            &app_prototype,
            &outer_cs_p_port,
        );
        assert!(result.is_err());

        assert_eq!(sr_p_connector.name(), Some("sr_p_connector".to_string()));
        assert_eq!(
            sr_p_connector.element().element_name(),
            ElementName::DelegationSwConnector
        );
    }

    #[test]
    fn test_assembly_sw_connector() {
        let model = AutosarModel::new();
        let _file = model.create_file("filename", AutosarVersion::LATEST).unwrap();
        let package = ArPackage::get_or_create(&model, "/package").unwrap();

        // create interfaces for the ports
        let sr_interface = SenderReceiverInterface::new("sr_interface", &package).unwrap();
        let cs_interface = ClientServerInterface::new("cs_interface", &package).unwrap();

        // create a composition and two application sw component types
        let composition = CompositionSwComponentType::new("composition", &package).unwrap();
        let swc_type_1 = ApplicationSwComponentType::new("app_type_1", &package).unwrap();
        let swc_type_2 = ApplicationSwComponentType::new("app_type_2", &package).unwrap();

        // create multiple ports with different interfaces and directions
        let swc1_sr_p_port = swc_type_1.create_p_port("swc1_sr_p_port", &sr_interface).unwrap();
        let swc2_sr_p_port = swc_type_2.create_p_port("swc2_sr_p_port", &sr_interface).unwrap();
        let swc1_sr_r_port = swc_type_1.create_r_port("swc1_sr_r_port", &sr_interface).unwrap();
        let swc2_sr_r_port = swc_type_2.create_r_port("swc2_sr_r_port", &sr_interface).unwrap();
        let swc1_sr_pr_port = swc_type_1.create_pr_port("swc1_sr_pr_port", &sr_interface).unwrap();
        let swc2_sr_pr_port = swc_type_2.create_pr_port("swc2_sr_pr_port", &sr_interface).unwrap();
        let swc1_cs_p_port = swc_type_1.create_p_port("swc1_cs_p_port", &cs_interface).unwrap();
        let swc2_cs_p_port = swc_type_2.create_p_port("swc2_cs_p_port", &cs_interface).unwrap();
        let swc1_cs_r_port = swc_type_1.create_r_port("swc1_cs_r_port", &cs_interface).unwrap();
        let swc2_cs_r_port = swc_type_2.create_r_port("swc2_cs_r_port", &cs_interface).unwrap();
        let swc1_cs_pr_port = swc_type_1.create_pr_port("swc1_cs_pr_port", &cs_interface).unwrap();
        let swc2_cs_pr_port = swc_type_2.create_pr_port("swc2_cs_pr_port", &cs_interface).unwrap();

        // add both application sw component types to the composition
        let app_prototype_1 = composition.create_component("app_prototype_1", &swc_type_1).unwrap();
        let app_prototype_2 = composition.create_component("app_prototype_2", &swc_type_2).unwrap();

        // connect the ports of the two application sw component types
        // SR: P -> R (valid)
        let _sr_p_r_connector = composition
            .create_assembly_connector(
                "sr_p_r_connector",
                &swc1_sr_p_port,
                &app_prototype_1,
                &swc2_sr_r_port,
                &app_prototype_2,
            )
            .unwrap();
        // SR: R -> P (valid)
        let _sr_r_p_connector = composition
            .create_assembly_connector(
                "sr_r_p_connector",
                &swc1_sr_r_port,
                &app_prototype_1,
                &swc2_sr_p_port,
                &app_prototype_2,
            )
            .unwrap();
        // SR: P -> PR (valid)
        let _sr_p_pr_connector = composition
            .create_assembly_connector(
                "sr_p_pr_connector",
                &swc1_sr_p_port,
                &app_prototype_1,
                &swc2_sr_pr_port,
                &app_prototype_2,
            )
            .unwrap();
        // SR: R -> PR (valid)
        let _sr_r_pr_connector = composition
            .create_assembly_connector(
                "sr_r_pr_connector",
                &swc1_sr_r_port,
                &app_prototype_1,
                &swc2_sr_pr_port,
                &app_prototype_2,
            )
            .unwrap();
        // SR: PR -> P (valid)
        let _sr_pr_p_connector = composition
            .create_assembly_connector(
                "sr_pr_p_connector",
                &swc1_sr_pr_port,
                &app_prototype_1,
                &swc2_sr_p_port,
                &app_prototype_2,
            )
            .unwrap();
        // SR: PR -> R (valid)
        let _sr_pr_r_connector = composition
            .create_assembly_connector(
                "sr_pr_r_connector",
                &swc1_sr_pr_port,
                &app_prototype_1,
                &swc2_sr_r_port,
                &app_prototype_2,
            )
            .unwrap();
        // CS: P -> R (valid)
        let _cs_p_r_connector = composition
            .create_assembly_connector(
                "cs_p_r_connector",
                &swc1_cs_p_port,
                &app_prototype_1,
                &swc2_cs_r_port,
                &app_prototype_2,
            )
            .unwrap();
        // CS: R -> P (valid)
        let _cs_r_p_connector = composition
            .create_assembly_connector(
                "cs_r_p_connector",
                &swc1_cs_r_port,
                &app_prototype_1,
                &swc2_cs_p_port,
                &app_prototype_2,
            )
            .unwrap();
        // CS: P -> PR (invalid)
        let cs_p_pr_connector_result = composition.create_assembly_connector(
            "cs_p_pr_connector",
            &swc1_cs_p_port,
            &app_prototype_1,
            &swc2_cs_pr_port,
            &app_prototype_2,
        );
        assert!(cs_p_pr_connector_result.is_err());
        // CS: R -> PR (valid)
        let _cs_r_pr_connector = composition
            .create_assembly_connector(
                "cs_r_pr_connector",
                &swc1_cs_r_port,
                &app_prototype_1,
                &swc2_cs_pr_port,
                &app_prototype_2,
            )
            .unwrap();
        // CS: PR -> P (invalid)
        let cs_pr_p_connector_result = composition.create_assembly_connector(
            "cs_pr_p_connector",
            &swc1_cs_pr_port,
            &app_prototype_1,
            &swc2_cs_p_port,
            &app_prototype_2,
        );
        assert!(cs_pr_p_connector_result.is_err());
        // CS: PR -> R (valid)
        let _cs_pr_r_connector = composition
            .create_assembly_connector(
                "cs_pr_r_connector",
                &swc1_cs_pr_port,
                &app_prototype_1,
                &swc2_cs_r_port,
                &app_prototype_2,
            )
            .unwrap();

        // SR: P -> P (invalid)
        let sr_p_p_connector_result = composition.create_assembly_connector(
            "sr_p_p_connector",
            &swc1_sr_p_port,
            &app_prototype_1,
            &swc2_sr_p_port,
            &app_prototype_2,
        );
        assert!(sr_p_p_connector_result.is_err());
        // SR: R -> R (invalid)
        let sr_r_r_connector_result = composition.create_assembly_connector(
            "sr_r_r_connector",
            &swc1_sr_r_port,
            &app_prototype_1,
            &swc2_sr_r_port,
            &app_prototype_2,
        );
        assert!(sr_r_r_connector_result.is_err());

        // connecting different interfaces is not allowed
        let result = composition.create_assembly_connector(
            "invalid_connector",
            &swc1_sr_p_port,
            &app_prototype_1,
            &swc2_cs_r_port,
            &app_prototype_2,
        );
        assert!(result.is_err());
    }

    #[test]
    fn test_pass_through_sw_connector() {
        let model = AutosarModel::new();
        let _file = model.create_file("filename", AutosarVersion::LATEST).unwrap();
        let package = ArPackage::get_or_create(&model, "/package").unwrap();

        // create interfaces for the ports
        let sr_interface = SenderReceiverInterface::new("sr_interface", &package).unwrap();
        let cs_interface = ClientServerInterface::new("cs_interface", &package).unwrap();

        // create a composition
        let composition = CompositionSwComponentType::new("composition", &package).unwrap();

        // create multiple ports with different interfaces and directions
        let sr_p_port = composition.create_p_port("sr_p_port", &sr_interface).unwrap();
        let sr_r_port = composition.create_r_port("sr_r_port", &sr_interface).unwrap();
        let cs_p_port = composition.create_p_port("cs_p_port", &cs_interface).unwrap();
        let cs_r_port = composition.create_r_port("cs_r_port", &cs_interface).unwrap();

        // connect the ports of the composition
        // SR: P -> R (valid)
        let _sr_p_r_connector = composition
            .create_pass_through_connector("sr_p_r_connector", &sr_p_port, &sr_r_port)
            .unwrap();
        // CS: R -> P (valid)
        let _cs_r_p_connector = composition
            .create_pass_through_connector("cs_r_p_connector", &cs_r_port, &cs_p_port)
            .unwrap();

        // connecting different interfaces is not allowed
        let result = composition.create_pass_through_connector("invalid_connector", &sr_p_port, &cs_r_port);
        assert!(result.is_err());
    }
}