Skip to content

Commit

Permalink
cxx-qt-gen: ensure that QObject is in the namespace map
Browse files Browse the repository at this point in the history
  • Loading branch information
ahayzen-kdab committed Sep 20, 2023
1 parent f810146 commit 010910b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/cxx-qt-gen/src/parser/cxxqtdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ impl ParsedCxxQtData {
),
);

// Ensure that the namespace of the QObject is in the mappings
if !qobject.namespace.is_empty() {
self.cxx_mappings.namespaces.insert(
foreign_alias.ident_left.to_string(),
qobject.namespace.clone(),
);
}

// Note that we assume a compiler error will occur later
// if you had two structs with the same name
self.qobjects
Expand Down
37 changes: 37 additions & 0 deletions crates/cxx-qt-gen/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,41 @@ mod tests {
let parser = Parser::from(module);
assert!(parser.is_err());
}

#[test]
fn test_cxx_qobject_namespace() {
let module: ItemMod = parse_quote! {
#[cxx_qt::bridge(namespace = "bridge_namespace")]
mod ffi {
extern "RustQt" {
#[qobject]
type MyObjectA = super::MyObjectARust;

#[qobject]
#[namespace = "type_namespace"]
type MyObjectB = super::MyObjectBRust;
}
}
};
let parser = Parser::from(module).unwrap();
assert_eq!(parser.cxx_qt_data.cxx_mappings.namespaces.len(), 2);
assert_eq!(
parser
.cxx_qt_data
.cxx_mappings
.namespaces
.get("MyObjectA")
.unwrap(),
"bridge_namespace"
);
assert_eq!(
parser
.cxx_qt_data
.cxx_mappings
.namespaces
.get("MyObjectB")
.unwrap(),
"type_namespace"
);
}
}

0 comments on commit 010910b

Please sign in to comment.