Skip to content

Commit a6aee85

Browse files
committed
[ISSUE mxsm#399]✅Add test case for topic_sys_flag🚀
1 parent 4362d45 commit a6aee85

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

rocketmq-common/src/common/sys_flag/topic_sys_flag.rs

+48
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,51 @@ pub fn clear_unit_sub_flag(sys_flag: u32) -> u32 {
5252
pub fn has_unit_sub_flag(sys_flag: u32) -> bool {
5353
(sys_flag & FLAG_UNIT_SUB) == FLAG_UNIT_SUB
5454
}
55+
56+
#[cfg(test)]
57+
mod tests {
58+
use super::*;
59+
60+
#[test]
61+
fn build_sys_flag_sets_correct_flags() {
62+
assert_eq!(build_sys_flag(true, false), FLAG_UNIT);
63+
assert_eq!(build_sys_flag(false, true), FLAG_UNIT_SUB);
64+
assert_eq!(build_sys_flag(true, true), FLAG_UNIT | FLAG_UNIT_SUB);
65+
}
66+
67+
#[test]
68+
fn set_unit_flag_sets_correct_flag() {
69+
let sys_flag = 0;
70+
assert_eq!(set_unit_flag(sys_flag), FLAG_UNIT);
71+
}
72+
73+
#[test]
74+
fn clear_unit_flag_clears_correct_flag() {
75+
let sys_flag = FLAG_UNIT;
76+
assert_eq!(clear_unit_flag(sys_flag), 0);
77+
}
78+
79+
#[test]
80+
fn has_unit_flag_returns_correct_value() {
81+
assert!(has_unit_flag(FLAG_UNIT));
82+
assert!(!has_unit_flag(FLAG_UNIT_SUB));
83+
}
84+
85+
#[test]
86+
fn set_unit_sub_flag_sets_correct_flag() {
87+
let sys_flag = 0;
88+
assert_eq!(set_unit_sub_flag(sys_flag), FLAG_UNIT_SUB);
89+
}
90+
91+
#[test]
92+
fn clear_unit_sub_flag_clears_correct_flag() {
93+
let sys_flag = FLAG_UNIT_SUB;
94+
assert_eq!(clear_unit_sub_flag(sys_flag), 0);
95+
}
96+
97+
#[test]
98+
fn has_unit_sub_flag_returns_correct_value() {
99+
assert!(has_unit_sub_flag(FLAG_UNIT_SUB));
100+
assert!(!has_unit_sub_flag(FLAG_UNIT));
101+
}
102+
}

0 commit comments

Comments
 (0)